【实验环境及需求】 1234OS 版本: centos7.9zabbix 版本: 4.0 LTS在 test 主机中使用 playbook 进行批量部署 zabbix-agent 【playbook 剧本】 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182---# playbook 中排除特定主机# - test:!10.101.20.87:!10.101.20.88# 批量部署zabbix-agent- hosts: test vars: IPAddress: "{{ ansible_bond1.ipv4.address }}" tasks: - name: disable firewalld service service: name: firewalld state: stopped enabled: no - name: temporary close selinux shell: /usr/sbin/setenforce 0 - name: permanent close selinux selinux: state: disabled - name: download zabbix rpm shell: /usr/bin/rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm && /usr/bin/yum clean all - name: install zabbix-agent package yum: name: zabbix-agent state: present - name: set service start on boot service: name: zabbix-agent state: started enabled: yes - name: modify zabbix-server host address lineinfile: path: "/etc/zabbix/zabbix_agentd.conf" regexp: '^Server=' line: "Server=10.243.20.51" notify: - Restart zabbix-agent - name: modify listen port lineinfile: path: "/etc/zabbix/zabbix_agentd.conf" regexp: '^# ListenPort' line: "ListenPort=10050" notify: - Restart zabbix-agent - name: modify Listen Address lineinfile: path: "/etc/zabbix/zabbix_agentd.conf" regexp: '^# ListenIP' line: "ListenIP=0.0.0.0" notify: - Restart zabbix-agent - name: modify StartAgents lineinfile: path: "/etc/zabbix/zabbix_agentd.conf" regexp: '^# StartAgents' line: "StartAgents=5" notify: - Restart zabbix-agent - name: modify Hostname is Local IP lineinfile: path: "/etc/zabbix/zabbix_agentd.conf" regexp: '^Hostname' line: "Hostname={{ IPAddress }}" notify: - Restart zabbix-agent handlers: - name: Restart zabbix-agent service: name: zabbix-agent state: restarted