agent_vars.yml config-agent.yml install-agent.yml main.yml
cat main.yml
- hosts: 193.168.120.71
become: yes
vars_files:
- agent_vars.yml
tasks:
- name: complie && install zabbix_agent
include: install-agent.yml
tags: step1
- name: config zabbix_agent
include: config-agent.yml
tags: step2
handlers:
- name: restart zabbix_agentd
service: name=zabbix_agentd state=restarted
cat agent_vars.yml
---
local_dir: /home/wn/example
tmp_dir: /tmp
install_dir: /usr/local/zabbix
server_ip: 193.168.120.56
cat install-agent.yml
#Step1: complie && install zabbix_agent
- name: copy zabbix package
copy: src={{local_dir}}/zabbix-3.0.3.tar.gz dest={{tmp_dir}}/zabbix-3.0.3.tar.gz
- name: add zabbix
shell: "groupadd zabbix; useradd -g zabbix zabbix"
ignore_errors: true
tags:
- add
- name: unpack zabbix package
shell: "yum -y install gcc; cd {{tmp_dir}} && if [ ! -d zabbix-3.0.3 ]; then tar -zxvf zabbix-3.0.3.tar.gz; fi"
ignore_errors: true
tags:
- unpack
- name: install agent
shell: "cd {{tmp_dir}}/zabbix-3.0.3 && ./configure --prefix={{install_dir}} --enable-agent && make install"
tags:
- install
cat config-agent.yml
---
#Step2: config zabbix_agent
- name: modify the config
shell: "sed -i 's/^Server=127.0.0.1/Server={{server_ip}}/' {{install_dir}}/etc/zabbix_agentd.conf && sed -i 's/^ServerActive=127.0.0.1/ServerActive={{server_ip}}/' {{install_dir}}/etc/zabbix_agentd.conf && sed -i 's/^Hostname=Zabbix server/Hostname={{inventory_hostname}}/' {{install_dir}}/etc/zabbix_agentd.conf"
tags:
- agent-config
- config
- name: modify system config
shell: "cp {{tmp_dir}}/zabbix-3.0.3/misc/init.d/tru64/zabbix_agentd /etc/init.d/ && chmod +x /etc/init.d/zabbix_agentd"
tags:
- system-config
- config
notify:
- restart zabbix_agentd
- name: create soft-link
shell: "ln -s {{install_dir}}/sbin/* /usr/local/sbin/ && ln -s {{install_dir}}/bin/* /usr/local/bin/"
tags:
- soft-link
ansible-playbook main.yml
本文介绍使用Ansible自动化配置及安装Zabbix Agent的过程。包括编译安装Zabbix Agent、配置Zabbix Agent并重启服务等内容。
3024

被折叠的 条评论
为什么被折叠?



