# Nagios XI downtime, use different list of servers every time

**URL:** <https://forum.ansible.com/t/nagios-xi-downtime-use-different-list-of-servers-every-time/6686>\
**Category:** Get Help\
**Created:** [June 20, 2024, 5:26pm UTC](https://forum.ansible.com/t/nagios-xi-downtime-use-different-list-of-servers-every-time/6686 "2024-06-20T17:26:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevb](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@kevb](https://forum.ansible.com/u/kevb)\
**Post date:** [June 20, 2024, 5:26pm UTC](https://forum.ansible.com/t/nagios-xi-downtime-use-different-list-of-servers-every-time/6686/1 "2024-06-20T17:26:56Z")

</div>

Hello all!

I’m trying to automate servers being put into downtime mode in Nagios XI (2024R1.1.3). I want to use an inventory file that changes, using a file that just has a list of servers generated the day before the patching event. I don’t want to have to update the /etc/ansible/hosts file every time, there will be 100’s of servers in each region.

For example:  
dev\_file:  
server1  
server 2

prod\_file:  
server3  
server4

I’m using ansible 2.9.27 on RedHat 8.10

Thanks!

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [July 1, 2024, 7:31pm UTC](https://forum.ansible.com/t/nagios-xi-downtime-use-different-list-of-servers-every-time/6686/2 "2024-07-01T19:31:55Z")

</div>

If you have control over the file generation, you can format the files like this

```auto
# assume this is called dev_file
all:
  hosts:
    server1:
    server2:

```

then run `ansible-playbook -i dev_file ......`

If you dont have control over the file, you can use a quick and dirty bash command:  
`ansible-playbook -i "$(cat dev_file | tr '\n' ', ')" ......`

You can also write a custom inventory plugin. As an example, use the python script below. The name `my_plugin` can be whatever makes sense for you, just make sure the filename matches.  
The file should be placed somewhere on the search path, as described here  
[https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#default-inventory-plugin-path](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-inventory-plugin-path)

```auto
# my_plugin.py
from ansible.plugins.inventory import BaseInventoryPlugin

class InventoryModule(BaseInventoryPlugin):

    NAME = 'my_plugin'

    def parse(self, inventory, loader, path, cache=True):
        super(InventoryModule, self).parse(inventory, loader, path)
        with open(path, 'r') as f:
            for line in f:
                self.inventory.add_host(f)

```

Then you can run `ansible-playbook -i dev_file ....` and it will read the file automatically.

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [July 1, 2024, 7:33pm UTC](https://forum.ansible.com/t/nagios-xi-downtime-use-different-list-of-servers-every-time/6686/3 "2024-07-01T19:33:23Z")

</div>

To be clear, this is assuming the files look like this

```auto
server1
server2
server3

```

If the format is different then my examples wont quite work.
