Search code examples
templatesfirefoxseleniumsalt-project

Salt Stack: templating in SLS files


I'm using Salt Stack for deployment purposes and need to deploy different browser versions to Selenium Grid nodes (e.g. Firefox 29.0 and 30.0). So from the Salt perspective I would like to use the following in top.sls:

base:
  'firefox29':
    - firefox
      - version: 29.0

  'firefox30':
    - firefox
      - version: 30.0

In this example we reuse firefox.sls state:

firefox:
  pkg.installed:
    - skip_verify: True
    - version: {{ version }}

I tried SLS files above with recent Salt (2014.1.7) and they are simply ignored (nothing is installed). When I remove version from firefox.sls it installs the latest Firefox.

Is it possible to somehow parameterize SLS states like in my example? I saw an issue on Github (https://github.com/saltstack/salt/issues/8878) describing the ways to do that with Jinja macro but didn't manage to use it for my situation.


Solution

  • You could do this with a jinja macro:

    firefox:
      pkg.installed:
      {% if grains['id'] == 'firefox29' %}
        - version: 29.0
      {% elif grains['id'] == 'firefox30' %}
        - version: 30.0
      {% endif %}
    

    If it gets any more complicated than that you should invest in learning pillars and keeping this sort of logic there. http://docs.saltstack.com/en/latest/topics/pillar/