User Tools

Site Tools


Salt&Cloud-Init Presentation

Name: Salt&Cloud-Init Presentation
Description: Salt & Cloud-Init presentation
Modification date :16/11/2018 &
Notify changes to:Owner and others


  • 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


Ejemplos de comandos

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

Real-life example: Centreon restarts windows on AS2 failure → Eventhandler en centreon: /usr/lib/centreon/plugins/eventhandlers/


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'

To get a list of the available grains run:

salt '*'

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…


sudo salt -G 'location:equinix'

Grains may also be used in jinja expressions.


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
  • Lamp state will install (at a glance):
    • http
    • mariadb
    • php
  • Open firewall ports
2019/07/18 07:15

Examples of states

top state



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:

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



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

linux/salt-stack/presenting_salt_and_cloudinit.txt · Last modified: 2022/02/11 11:36 by