ansible 安装zabbix 并且 自启动

---
- hosts: all
remote_user: root
gather_facts: false
tasks:
- name: copy zabbix-3.2.11 to agent
copy: src=/opt/soft/zabbix/zabbix-3.2.11 dest=/usr/local/ remote_src=yes
- name: chmod +x to sbin/zabbix_agentd
shell: chmod +x /usr/local/zabbix-3.2.11/sbin/zabbix_agentd
- name: copy zabbix-agent to agent
copy: src=/opt/soft/zabbix/zabbix_agentd dest=/etc/init.d/ remote_src=yes
- name: chmod +x to init.d/zabbix_agentd
shell: chmod +x /etc/init.d/zabbix_agentd
- name: "获取伪随机zabbix_proxy_ip"
set_fact:
zabbix_proxy_ip: "{{ item }}"
with_random_choice:
- 172.16.255.145
- 172.16.255.146
- 172.16.255.147
- name: "修改配置文件里的Server为随机zabbix_proxy_ip地址"
lineinfile:
dest: /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf
regexp: "^Server=.*"
line: "Server={{ zabbix_proxy_ip }}"
backup: yes
- name: "修改配置文件里的ServerActive为随机zabbix_proxy_ip地址"
lineinfile:
dest: /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf
regexp: "^ServerActive=.*"
line: "ServerActive={{ zabbix_proxy_ip }}"
backup: yes
- name: "修改配置文件里的Hostname为本地IP地址"
lineinfile:
dest: /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf
regexp: "^Hostname=.*"
line: "Hostname={{ inventory_hostname }}"
backup: yes
- name: "设置zabbix_agentd自启动"
lineinfile:
dest: /etc/rc.local
line: "/etc/init.d/zabbix_agentd start"
state: present
- name: "确保rc.local具有可执行权限"
file:
path: /etc/rc.d/rc.local
mode: 0755
- name: "创建/var/log/zabbix目录存放log和pid文件"
file:
path: /var/log/zabbix
state: directory
mode: 0755
- name: "启动新版本的zabbix-agent"
shell: "/sbin/service zabbix_agentd restart"

 

posted @ 2020-12-01 16:45  大福920917  阅读(150)  评论(0)    收藏  举报