Search code examples
ansiblezabbix

Zabbix maintenance using Ansible


I would like to use the zabbix _maintenance module.

But I want to send the host_groups as an extra var so I can put multiple host groups in maintenance.

The problem I faced is that the host_group needs a list of items and I can't understand how to write the role so it will run over a list given to it by the extra var

I tried :

- name: maintenance
   zabbix_maintenance:
    name: Pause
    host_groups:
      - "{{ item }}"
    with_items:
      - { 'zabbix_hosts_groups' }
    state: "{{ zabbix_state }}"
    server_url: http://zabbix.XXX.com
    login_user: YYY
    login_password: XXX
    minutes: 90
    desc: "Paused-for-dep"

and running it:

 ansible-playbook -i 'localhost,' --connection=local zabbix-maintenance.yml -e '{"zabbix_hosts_groups":"Test1","Test2"}' -e 'zabbix_state=present

Solution

  • Syntactically correct task definition would be:

    - name: maintenance
      zabbix_maintenance:
        name: Pause
        host_groups: "{{ zabbix_hosts_groups }}"
        state: "{{ zabbix_state }}"
        server_url: http://zabbix.XXX.com
        login_user: YYY
        login_password: XXX
        minutes: 90
        desc: "Paused-for-dep"
    

    I don't understand the problem description though. "Jenkins"??? "How to write the role"??? Please at least learn the vocabulary required to ask a question.