本文是根據以下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
如下:
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 %}