User Tools

Site Tools


salt-stack:presenting_salt_and_cloudinit

Salt&Cloud-Init Presentation

Documentation
Name: Salt&Cloud-Init Presentation
Description: Salt & Cloud-Init presentation
Modification date :16/11/2018
Owner:dodger@ciberterminal.net & warlock86@gmail.com
Notify changes to:Owner and others
Tags:

Index

  • Definición de la arquitectura
  • Ejemplos de comandos
    • Ejemplo de uso: Que centreon reinicie un windows cuando falla AS2 (ya está hecho)
  • Grains
  • Ejemplo de states
  • jinja
  • ¿salt-reactor?
  • ¿pillars?
  • Bonus track

Architecture

Ejemplos de comandos

See internal documentation: Useful SALT commands (cheatsheet) and recipes

Real-life example: Centreon restarts windows on AS2 failure

@warlock86@gmail.com → Eventhandler en centreon: /usr/lib/centreon/plugins/eventhandlers/salt_restart_as2.sh

Grains

Grains is an interface that provides information specific to a minion. The information available through the grains interface is static and gets loaded then the Salt minion starts. The information that Grains store could be about the running kernel, the operating system or other attributes of the running host.

Gran information can be useful for targeting using the -G parameter.

For example, to run a command in every Centos server, you can match the grain os and it'ts content Centos like this:

salt -G 'os:Centos' test.ping

To get a list of the available grains run:

salt '*' grain.ls

Or to get the content of the items:

salt '*' grain.items

There are two type of grains:

  • Core: that are those included by default by salt
  • Custom: that can be set by including them in /etc/salt/grains or the minion configuration. Here you can set something like the location, the virtualization cluster, the environment…

Example:

sudo salt -G 'location:equinix' test.ping

Grains may also be used in jinja expressions.

States

This section is a document inclusion of SALT states

Quick description

Salt states are a set of:

  • Packages
  • Files
  • Commands
  • Configurations

That will be applied to any machine (minion) so that machine can:

  • perform some set of actions
  • take some pre-configured role
Example
  • Lamp state will install (at a glance):
    • http
    • mariadb
    • php
  • Open firewall ports
2019/07/18 09:15

Examples of states

top state

Platataformation

Jinja

Jinja is a standard template language.
SaltStack support Jinja for templating :-) AND scripting

Using Jinja we're able to use grains to match whatever and execute commands as consequence.
For example, install different package on different linux distros:

vimrc.sls
vimrc:
  pkg.installed:
    {% if grains['os'] == 'Ubuntu' or grains['os'] == 'Debian' %}
    - name: vim
    {% else %}
    - name: vim-enhanced
    {% endif %}
  file.managed:
    {% if grains['os'] == 'Ubuntu' or grains['os'] == 'Debian' %}
    - name: /etc/vim/vimrc
    {% else %}
    - name: /etc/vimrc
    {% endif %}
    - source: salt://bofher_defaults/vimrc

salt-reactor

pillars

Quote from the official documentation:

Pillars are tree-like structures of data defined on the Salt Master and passed through to minions. They allow confidential, targeted data to be securely sent only to the relevant minion.











Bonus track

salt-stack/presenting_salt_and_cloudinit.txt · Last modified: 2019/07/18 09:21 by dodger