---标签:when,zabbix,ansible,agent2,6.0,distribution From: https://blog.51cto.com/dayu/5730398
- name: install agent
hosts: all
vars:
server_host: "192.168.100.206"
tasks:
- shell: "rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm ; dnf clean all"
when: ansible_distribution_file_variety == "RedHat" and ansible_distribution_major_version == "8"
- shell: "rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm ; yum clean all"
when: ansible_distribution_file_variety == "RedHat" and ansible_distribution_major_version == "7"
- shell: "wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu20.04_all.deb; dpkg -i zabbix-release_6.0-4+ubuntu20.04_all.deb "
when: ansible_distribution_file_variety == "Debian" and ansible_distribution_major_version == "20"
- yum:
name:
- "zabbix-agent2"
- "zabbix-agent2-plugin-mongodb"
disable_gpg_check: yes
state: present
when: ansible_distribution_file_variety == "RedHat"
- apt:
name:
- "zabbix-agent2"
- "zabbix-agent2-plugin-mongodb"
update_cache: yes
state: present
when: ansible_os_family == "Debian"
- replace:
path: /etc/zabbix/zabbix_agent2.conf
regexp: 'Server=127.0.0.1'
replace: "Server={{ server_host }}"
- service:
name: zabbix-agent2
state: restarted
enabled: yes