diff --git a/defaults/main.yml b/defaults/main.yml index fd0c74e..6e632d7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,6 +5,10 @@ zabbix_repo_version: '4.0' zabbix_agent_ubuntu_repo: 'https://repo.zabbix.com/zabbix/{{ zabbix_repo_version }}/{{ ansible_distribution | lower }}/pool/main/z/zabbix-release/zabbix-release_{{ zabbix_repo_version }}-2+{{ ansible_distribution_release }}_all.deb' zabbix_agent_centos_repo: 'https://repo.zabbix.com/zabbix/{{ zabbix_repo_version }}/rhel/{{ ansible_distribution_major_version }}/x86_64/zabbix-release-{{ zabbix_repo_version }}-1.el7.noarch.rpm' +zabbix_agent_packages: + - 'zabbix-agent' + - 'zabbix-release' + zabbix_agent_conf_dir: /etc/zabbix zabbix_agent_include_conf_dir: '{{ zabbix_agent_conf_dir }}/zabbix_agentd.d' zabbix_agent_log_dir: '/var/log/zabbix' diff --git a/tasks/main.yml b/tasks/main.yml index 7109623..ca93f1b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,11 @@ --- +- name: Check if the zabbix repository is installed + package_facts: + manager: "auto" + when: + - zabbix_agent_install | bool + tags: [ 'zabbix', 'zabbix_agent' ] + - import_tasks: zabbix-agent-deb.yml when: - zabbix_agent_install | bool diff --git a/tasks/zabbix-agent-deb.yml b/tasks/zabbix-agent-deb.yml index 2e00761..fa405b3 100644 --- a/tasks/zabbix-agent-deb.yml +++ b/tasks/zabbix-agent-deb.yml @@ -2,14 +2,15 @@ - name: Repository and packages, deb/ubuntu block: - name: Install the repository - apt: deb={{ zabbix_agent_ubuntu_repo }} state=latest + apt: deb={{ zabbix_agent_ubuntu_repo }} state=present register: update_apt_cache + when: "'zabbix-release' not in ansible_facts.packages" - name: Update the apt cache if we just installed the repository apt: update_cache=yes - when: update_apt_cache is changed + when: update_apt_cache is defined and update_apt_cache is changed - name: Install the Zabbix agent package - apt: pkg=zabbix-agent state=latest cache_valid_time=1800 + apt: pkg={{ zabbix_agent_packages }} state=latest cache_valid_time=1800 tags: [ 'zabbix', 'zabbix_agent' ] diff --git a/tasks/zabbix-agent-rh.yml b/tasks/zabbix-agent-rh.yml index 806f1ac..ff1b8de 100644 --- a/tasks/zabbix-agent-rh.yml +++ b/tasks/zabbix-agent-rh.yml @@ -2,9 +2,10 @@ - name: Repository and packages, RH/CentOS block: - name: Install the repository - yum: name={{ zabbix_agent_centos_repo }} state=latest + yum: name={{ zabbix_agent_centos_repo }} state=present + when: "'zabbix-release' not in ansible_facts.packages" - name: Install the Zabbix agent package - yum: name=zabbix-agent state=latest + yum: name={{ zabbix_agent_packages }} state=latest tags: [ 'zabbix', 'zabbix_agent' ]