ansible-playbook 用法
cat install_zabbix_3.yaml
---
- name:#名称
hosts: new #hosts为文件名,new为hosts文件里得[new]
tasks:#任务
- name:
shell: |
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum clean all
- name:
yum:
name: zabbix-agent
state: latest
- lineinfile: #替换
path: /etc/zabbix/zabbix_agentd.conf #替换文件路径
regex: '^Server=' #替换得匹配
line: 'Server=10.16.1.4' 替换成
- lineinfile:
path: /etc/zabbix/zabbix_agentd.conf
regex: '^ServerActive='
line: 'ServerActive=10.16.1.4'
- lineinfile:
path: /etc/zabbix/zabbix_agentd.conf
regex: '^Hostname='
line: Hostname = {{ inventory_hostname }}
- service:
name: zabbix-agent
state: started #启动
enabled: yes #开启自启动