Nagios module usage

I’d like to set downtime in Nagios for several hosts at once using the Nagios module. How do I specify those several hosts?

- nagios: action=downtime minutes=30 service=all host=?

Many thanks.

you can do:

- nagios: action=downtime minutes=30 service=all host={{item}}
  with_items: "{{ listofhosts }}"

or if it is a specific ansible inventory group:

- nagios: action=downtime minutes=30 service=all host={{item}}
  with_items: "{{ groups['specificgroup'] }}"

Excellent - thank you, Brian!

Oh, Brian, is the {{ listofhosts }} just a space-delimited list?

its a list

listofhosts:
  - host1
  - host2

or

listofhosts: [ 'host1', 'host2', ....]

Sorry I’m asking Ansible 101 questions, but my play isn’t working:

tasks:

  • nagios: action=downtime minutes=5 author=“My Name” service=all host={{item}}
    with_items: “{{ listofhosts }}”
    listofhosts:
  • summitauto
    delegate_to: nagios_server
    tags:
  • nagios_downtime

I guess I don’t know where to put my list. Also not sure if “author” belongs where I have it.

you cannot define it that way, you either predefine the list in a
vars: or vars_file or just do it like this:

  tasks:
    - nagios: action=downtime minutes=5 author="My Name" service=all
host={{item}}
      with_items:
         - summitauto
      delegate_to: nagios_server
      tags:
         - nagios_downtime

When I try that, I get the following errors:

fatal: [host1 → nagios_server] => Authentication failure.
fatal: [host2 → nagios_server] => Authentication failure.
fatal: [host3 → nagios_server] => Authentication failure.
changed: [host4 → nagios_server] => (item=summitauto)
changed: [host5 → nagios_server] => (item=summitauto)
changed: [host6 → nagios_server] => (item=summitauto)

That’s clearly not what I’m after. The beginning of the playbook looks like this:

  • hosts: all
    gather_facts: false
    sudo: yes

and I run the playbook like this: ansible-playbook someplaybook.yml --tags “nagios_downtime” -u sudoacct

Thanks for your continuing help.

I didn’t realize that I needed to create a separate play in my playbook to do this piece. Once I did that, everything worked as advertise. Sorry that my learning mistakes have created noise. Thanks, again, to Brian Coca for all the help - greatly appreciated!