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

salt分组推送

时间:2017-05-11 22:36:04      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:salt   分组推送   

在salt,minion正常连接情况下

              在/srv/salt/下创建union.sls nginx.sls 和 bind.sls

                           union.sls如下:

                                      include:

- nginx

- bind

                           nginx.sls如下:

                               

{%- if ( grains[‘host‘] == "hw_1" ) %}

nginx:

pkg:

- name: nginx

- installed

service:

- name: nginx

- running

- reload: True

- watch:

- file: /etc/nginx/nginx.conf

/etc/nginx/nginx.conf:

file.managed:

- source: salt://files/nginx/nginx.conf

- user: root

- mode: 644

- backup: minion

{%- endif %}

  bind.sls如下:

                                             

{%- if ( grains[‘host‘] == "hw_2" ) %}

bind:

pkg:

- installed

named:

service:

- running

- reload: True

- enable: True

- watch:

- file: /etc/named.conf

- file: /var/named/1.1.1.in-addr.arpa

- file: /var/named/2.2.2.in-addr.arpa

- file: /var/named/optest1.com

- file: /var/named/optest2.com

/etc/named.conf:

file.managed:

- source: salt://files/named/named.conf

- user: named

- mode: 644

- backup: minion

/var/named/1.1.1.in-addr.arpa:

file.managed:

- source: salt://files/named/1.1.1.in-addr.arpa

- user: root

- mode: 644

- backup: minion

/var/named/2.2.2.in-addr.arpa:

file.managed:

- source: salt://files/named/2.2.2.in-addr.arpa

- user: root

- mode: 644

- backup: minion

/var/named/optest1.com:

file.managed:

- source: salt://files/named/optest1.com

- user: root

- mode: 644

- backup: minion

/var/named/optest2.com:

file.managed:

- source: salt://files/named/optest2.com

- user: root

- mode: 644

- backup: minion

{%- endif %}

测试命令:salt ‘*‘ state.sls union test=true

注重点:

1.- watch

-file: /var/named/optest2.com 指定的是minion的目录

2./etc/named.conf:指定的是minion的目录需要被替换的目录而非master的目录

3.source: salt://files/named/named.conf 是指master的/srv/salt/files/named/named.conf

4.使用grains[‘host‘] 获取minion主机名进行判断,将minion主机名更名为ID

第二种方法:

只创建一个文件夹union.sls

{%- if ( grains[‘host‘] == "hw_1" ) %}

nginx:

pkg:               #定义使用(pkg state module)

- name: nginx    #安装nginx(yum安装)

- installed

named:

service:   #保持服务是启动状态

- name: nginx

- running

- reload: True

- watch:

- file: /etc/nginx/nginx.conf

/etc/nginx/nginx.conf:       #绝对路径

file.managed:

- source: salt://files/nginx/nginx.conf  #nginx.conf配置文件在salt上面的位置

- user: root

- mode: 644

- backup: minion

{%- endif %}

{%- if ( grains[‘host‘] == "hw_2" ) %}

bind:

pkg:

- installed

service:

- running

- reload: True

- watch:

- file: /etc/named.conf

- file: /var/named/1.1.1.in-addr.arpa

- file: /var/named/2.2.2.in-addr.arpa

- file: /var/named/optest1.com

- file: /var/named/optest2.com

/etc/named.conf:

file.managed:

- source: salt://files/named/named.conf

- user: named

- mode: 644

- backup: minion

/var/named/1.1.1.in-addr.arpa:

file.managed:

- source: salt://files/named/1.1.1.in-addr.arpa

- user: root

- mode: 644

- backup: minion

/var/named/2.2.2.in-addr.arpa:

file.managed:

- source: salt://files/named/2.2.2.in-addr.arpa

- user: root

- mode: 644

- backup: minion

/var/named/optest1.com:

file.managed:

- source: salt://files/named/optest1.com

- user: root

- mode: 644

- backup: minion

/var/named/optest2.com:

file.managed:

- source: salt://files/named/optest2.com

- user: root

- mode: 644

- backup: minion

{%- endif %}


本文出自 “12667403” 博客,谢绝转载!

salt分组推送

标签:salt   分组推送   

原文地址:http://12677403.blog.51cto.com/12667403/1924726

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