码迷,mamicode.com
首页 > 其他好文 > 详细

SaltStack的配置管理--jinja

时间:2018-01-20 17:47:26      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:less   running   sls   fun   ipad   http   etc   2.3   art   

SaltStack的配置管理--jinja

需求场景:使用jinja模板,让各节点的httpd都监听在本机的ip

[root@linux-node1 apache]# vim files/httpd.conf 
配置文件修改监听的ip地址和端口以变量的形式
Listen {{ IPADDR }}:{{ PORT }}

[root@linux-node1 apache]# vim init.sls 
apache-install:
  pkg.installed:
    - name: httpd

apache-config:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://apache/files/httpd.conf
    - user: root
    - group: root
    - mode: 644
    - template: jinja------------------>声明这个是模板
    - defaults:------------------------>定义默认的参数和值
      PORT: 80------------------------->PORT和IPADDR都为变量
      IPADDR: {{ grains[‘fqdn_ip4‘][0] }}---->通过grains返回数据,此处返回的是一个列表形式,增加[0]指定第一个

apache-auth:
  pkg.installed:
    - name: httpd-tools
  cmd.run:
    - name: htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin
    - unless: test -f /etc/httpd/conf/htpasswd_file

apache-service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:
      - file: apache-config

[root@linux-node1 apache]# salt -S "192.168.56.11" state.highstate
----------
          ID: apache-config
    Function: file.managed
        Name: /etc/httpd/conf/httpd.conf
      Result: True
     Comment: File /etc/httpd/conf/httpd.conf updated
     Started: 11:14:08.537957
    Duration: 25.518 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -42,7 +42,7 @@
                   # prevent Apache from glomming onto all bound IP addresses.
                   #
                   #Listen 12.34.56.78:80
                  -Listen 80
                  +Listen 192.168.56.11:80---->更改为监听本机ip地址,端口为80

                   #
                   # Dynamic Shared Object (DSO) Support

[root@linux-node1 apache]# netstat -tulnp|grep httpd
tcp        0      0 192.168.56.11:80        0.0.0.0:*               LISTEN      6837/httpd          
[root@linux-node1 apache]# vim /srv/salt/base/top.sls 
prod:
  ‘linux-node*.example.com‘:
    - lamp
[root@linux-node1 apache]# salt ‘*‘ state.highstate
[root@linux-node2 ~]# netstat -tulnp |grep httpd
tcp        0      0 192.168.56.12:80        0.0.0.0:*               LISTEN      16447/httpd         

总结:
1.修改httpd.conf配置
2.修改sls增加:
- template: jinja
  - defaults:
    PORT: 80
    IPADDR: {{ grains[‘fqdn_ip4‘][0] }}

SaltStack的配置管理--jinja

标签:less   running   sls   fun   ipad   http   etc   2.3   art   

原文地址:http://blog.51cto.com/jinlong/2063207

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!