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 %}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章