---

- when: zabbix_agent2 and zabbix_agent_installed.stat.exists
  block:
    - name: Stop zabbix-agent
      service: name=zabbix-agent state=stopped enabled=False

    # Note : don't remove it as it'll be pulled as a dependency of zabbix-agent-addons
  tags: zabbix

- when: not zabbix_agent2 and zabbix_agent2_installed.stat.exists
  block:
    - name: Stop zabbix-agent2
      service: name=zabbix-agent2 state=stopped enabled=False

    - name: Remove zabbix-agent2
      package:
        name:
          - zabbix-agent2
        state: absent

  tags: zabbix

- name: Install zabbix-agent
  package:
    name:
      - "{{ (zabbix_agent2) | ternary('zabbix-agent2', 'zabbix-agent') }}"
    state: "{{ zabbix_agent_update | ternary('latest', 'present') }}"
  notify: restart zabbix-agent
  tags: zabbix
