States sls进阶

本文是根据以下URL 的写出:

http://docs.saltstack.com/topics/tutorials/states_pt3.html

States SLS 可以有很多种写法,如

1,Templating SLS modules

默认States 模板文件是根据Jinja2来书写的,如下:

{% for usr in 'moe','larry','curly' %}
{{ usr }}:
  user.present
{% endfor %}

这个模板文件产生如下格式的数据:

moe:
  user.present
larry:
  user.present
curly:
  user.present


2,Using Grains in sls modules

如下:

apache:
  pkg.installed:
    {% if grains['os'] == 'RedHat' %}
    - name: httpd
    {% elif grains['os'] == 'Ubuntu' %}
    - name: apache2
    {% endif %}

根据OS的版本来匹配

3,calling salt modules from templates

{% for usr in 'moe','larry','curly' %}
{{ usr }}:
  group:
    - present
  user:
    - present
    - gid: {{ salt['file.group_to_gid'](usr) }}
    - require:
      - group: {{ usr }}
{% endfor %}




你可能感兴趣的:(States sls进阶)