saltstack的自动化推送及配置文件更改推送
自动化推送cd /srv/salt/mkdir _grainscd _grains/vim my_grains.py#!/usr/bin/env pythondef my_grains():grains = {}grains['hello'] = 'world'grains['salt'] = 'stack'return grainssalt...
·
自动化推送
cd /srv/salt/
mkdir _grains
cd _grains/
vim my_grains.py
#!/usr/bin/env python
def my_grains():
grains = {}
grains['hello'] = 'world'
grains['salt'] = 'stack'
return grains
salt server10 saltutil.sync_grains
在server10上查看
查询推送信息
salt ‘*’ grains.item hello
salt ‘*’ grains.item salt
vim /etc/salt/master
mkdir /srv/pillar
cd /srv/pillar
mkdir web
cd web/
vim install.sls
{% if grains['fqdn'] == 'server10' %}
webserver: httpd
{% elif grains['fqdn'] == 'server8' %}
webserver: nginx
{% endif %}
vim top.sls
base:
'*':
- web.install
/etc/init.d/salt-master restart
salt '*' saltutil.refresh_pillar
查看
salt 'server10' pillar.items
salt 'server8' pillar.items
salt '*' pillar.items
salt -G 'roles:apache' test.ping
salt -G 'roles:nginx' test.ping
salt -I 'webserver:nginx' test.ping
salt -I 'webserver:httpd' test.ping
saltstack的自动化推送更改配置文件
方法一
cd /srv/salt/httpd/
vim install.sls
/etc/httpd/conf/httpd.conf:
file.managed:
- source: salt://httpd/files/httpd.conf
- mode: 664
- user: root
- template: jinja # 必须导入这个模板
- context:
bind: 172.25.11.9
port: 80
vim /srv/salt/httpd/files/httpd.conf
salt server10 state.sls httpd.install
方法二
cd /srv/salt/httpd/
vim lib.sls
{% set port = 80 %}
在/srv/salt/httpd/files/httpd.conf的文件首行写入
{% from 'httpd/lib.sls' import port with context %}
salt server10 state.sls httpd.install
方法三
cd /srv/salt/httpd/
vim install.sls
vim /srv/salt/httpd/files/httpd.conf
注释掉首行(最好删除)
Listen {{ grains['ipv4'][-1] }}:{{ port }} # 截取ipv4列表的最后一个元素
推送 salt server10 state.sls httpd.install
方法四
cd /srv/salt/httpd/
vim /srv/pillar/web/install.sls
{% if grains['fqdn'] == 'server10' %}
webserver: httpd
bind: 172.25.11.10
port: 9090
{% elif grains['fqdn'] == 'server8' %}
webserver: nginx
{% endif %}
vim install.sls
/etc/httpd/conf/httpd.conf:
file.managed:
- source: salt://httpd/files/httpd.conf
- mode: 664
- user: root
- template: jinja
- context:
bind: {{ pillar['bind'] }}
port: {{ pillar['port'] }}
vim files/httpd.conf
Listen {{ pillar['bind'] }}:{{ pillar['port'] }}
salt server10 state.sls httpd.install
更多推荐
已为社区贡献1条内容
所有评论(0)