需求:想讓saltstack的file模塊分發到minion端的配置文件監聽minion端的IP和端口,如何用變量實現?看下面!!php
# cat lamp.sls lamp-install: pkg.installed: - pkgs: - httpd - php - php-pdo - php-mysql apache-config: file.managed: - name: /etc/httpd/conf/httpd.conf - source: salt://web/files/httpd.conf - user: root - group: root - mode: 644 - template: jinja #指定使用jinja模板 - defaults: #變量列表 PORT: 80 #端口變量 IPADDR: {{ grains['fqdn_ip4'][0] }} #ip變量{此變量使用grains獲取的IP地址} - require: - pkg: lamp-install apache-auth: pkg.installed: - name: httpd-tools - require_in: -cmd: apache-auth cmd.run: - name: htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin - unless: test -f /etc/httpd/conf/htpasswd_file apache-conf: file.recurse: - name: /etc/httpd/conf.d - source: salt://web/files/apache-conf.d - watch_in: - service: lamp-service php-config: file.managed: - name: /etc/php.ini - source: salt://web/files/php.ini - user: root - group: root - mode: 644 - watch_in: - service: lamp-service lamp-service: service.running: - name: httpd - enable: True - reload: True - watch: - file: apache-conf - file: apache-config
1.一、修改apache-config狀態下的source指定的配置文件mysql
# sed -n '42p' /srv/salt/base/web/files/httpd.conf Listen {{ IPADDR }}:{{ PORT }}
注:將以前的Listen 80改成Listen {{ IPADDR }}:{{ PORT }}web