Jinja2

Two main types of Jinja2 syntaxes used in Salt:


Making use of Jinja2 templates in a State file

Jinja2 templates allow us to produce states that are platform agnostic by dynamically choosing the correct content for our state files.

Making use of Grains, we can retrieve the OS type that we are dealing with. With the grains plus the Jinja template, we can specify that if an OS is from a certain type, install X, if it's other type, install Y.

Using grains and Jinja2, we get something like this:

Make sure apache is running:
  service.running:
    - name: apache2
    - enable: True
    - require: 
       - pkg.apache_installation

apache_installation:
  pkg.installed:
    - name: apache2
install_apache:    
  pkg.installed:  
   {% if grains['os_family'] == 'Debian' %}      
	- name: apache2  
    {% elif grains['os_family'] == 'RedHat' %}      
        - name: httpd 
   {% endif %}

Defining secure minion-specific data in pillar

System to give minion-sensitive data.

Pillar data is sensitive data. Holds per-minion data, custom data for each minion.