系统初始化模块--------------zabbix-agent
在配置文件里设置pillar路径
[root@node1 init]# vim /etc/salt/master
pillar_roots:
base:
- /srv/pillar/base
[root@node1 init]# /etc/init.d/salt-master restart
在pillar里建立top.sls和zabbix.sls
[root@node1 init]# mkdir /srv/pillar/base
[root@node1 pillar]# cd base/
[root@node1 base]# cat top.sls
base:
‘*‘:
- zabbix
[root@node1 base]# cat zabbix.sls
zabbix-agent:
Zabbix_Server: 192.168.10.129
[root@node1 init]# cd /srv/salt/base/init/
[root@node1 init]# cat zabbix_agent.sls
zabbix-agent-install:
pkg.installed:
- name: zabbix-agent
file.managed:
- name: /etc/zabbix/zabbix_agentd.conf
- source: salt://init/files/zabbix_agentd.conf
- template: jinja
- defaults:
Server: {{ pillar[‘zabbix-agent‘][‘Zabbix_Server‘] }} #这里将pillar里ID为zabbix-agent,Zabbix_Server的值赋给变量Server
- require:
- pkg: zabbix-agent-install
service.running:
- name: zabbix-agent
- enable: True
- watch:
- pkg: zabbix-agent-install
- file: zabbix-agent-install
编写配置文件利用jinja将Server变量的值传给Server,也就是指定zabbix-Server地址
cp /etc/zabbix/zabbix_agentd.conf /srv/salt/base/init/files/
[root@node1 base]#vim /srv/salt/base/init/files/zabbix_agent.conf
Server={{Server}}
将zabbix_agent.sls include到env_init.sls
[root@node1 init]# cat env_init.sls
include:
- init.dns
- init.history
- init.audit
- init.sysctl
- init.zabbix_agent
[root@node1 init]# salt ‘*‘ state.highstate
本文出自 “feng” 博客,请务必保留此出处http://fengxiaoli.blog.51cto.com/12104465/1958159
原文地址:http://fengxiaoli.blog.51cto.com/12104465/1958159