####salt配置rest
salt-master:code
salt-minion:server
####安裝salt-master及salt-minion並accecpt key.ip
####修改master的配置get
file_roots: base: - /srv/salt/base dev: - /srv/salt/dev prod: - /srv/salt/prod pillar_roots: base: - /srv/pillar/base dev: - /srv/pillar/dev prod: - /srv/pillar/prod
2.建立文件夾it
#mkdir -p /srv/salt/{base,dev,prod} #mkdir -p /srv/pillar/{base,dev,prod}
3.重啓salt-masterio
# service salt-master restart Stopping salt-master daemon: [ OK ] Starting salt-master daemon: [ OK ]
1.建立pillar使用的sls 在/srv/pillar/base目錄下建立top.sls及zabbixagent.sls cat top.slsast
base: #base環境 'L@ops1,192.168.10.92': #列表匹配,匹配ops1及192.168.10.92 - zabbixagent #引用zabbixagent.sls或者zabbixagent/init.sls
cat zabbixagent.sls模板
zabbix-agent: serverhost: 192.168.10.91 #參數 serverport: 10050 #參數
2.查看全部pillar,能夠看出,只有ops1和92匹配到了zabbix-agent的pillar #salt '*' pillar.item zabbix-agenttest
192.168.10.94: ---------- 192.168.10.95: ---------- 192.168.10.93: ---------- 192.168.10.92: ---------- zabbix-agent: ---------- serverhost: 192.168.10.91 serverport: 10050 ops1: ---------- zabbix-agent: ---------- serverhost: 192.168.10.91 serverport: 10050
1.在/src/salt/base中建立文件
echo 123 >/src/salt/base/test.txt
2.使用salt去cp文件至minion # salt -E 'op*' cp.get_file salt://test.txt /tmp/test.txt
ops1: /tmp/test.txt
1.在/srv/salt/base目錄下建立top.sls,testjinja.sls cat top.sls
base: '*': - zabbix-agent-init - testjinja
cat testjinja.sls
testfile: file.managed: - name: /tmp/test.txt - source: salt://test.txt - template: jinja - defaults: zabbixserverport: {{ pillar['zabbix-agent']['serverport'] }} zabbixserverhost: {{ pillar['zabbix-agent']['serverhost'] }}
2.使用jinja生成模板 #salt 'ops1' state.sls test.jinja
ops1: ---------- ID: testfile Function: file.managed Name: /tmp/test.txt Result: True Comment: File /tmp/test.txt updated Started: 17:55:59.683959 Duration: 160.869 ms Changes: ---------- diff: --- +++ @@ -1,0 +1,2 @@ +192.168.10.91 +10050 Summary ------------ Succeeded: 1 (changed=1) Failed: 0 ------------ Total states run: 1
3.查看test.txt文件發現已改變
192.168.10.91 10050