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.
# 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.