How to get inventory path in call back plugin:
I found this, however it is not working… I’m developing my plugin where I need inventory path to work on other things. Any help will be appreciated
In short, is there a way to check which parameter is used for what in
v2_playbook_on_start(self, playbook):
On Ansible v2, Ansible doesn’t set self.playbook automatically
|
|
self.playbook = playbook
|
|
|
|
playbook_file_name = self.playbook._file_name
|
|
inventory = self._options.inventory
|
|
|
|
self.start_timer()
|
|
|
|
Set the playbook name from its filename
|
|
self._playbook_name, _ = os.path.splitext(
|
|
os.path.basename(playbook_file_name))
|
|
if isinstance(inventory, list):
|
|
inventory = ‘,’.join(inventory)
|
|
self._inventory_name = ‘,’.join([os.path.basename(os.path.realpath(name)) for name in inventory.split(‘,’) if name])
|
Any help immediately will be appreciated
If you want “immediate” help, then a mailing list is often not the right place to go.
There is no “official” way to get the name of the inventory file from a callback plugin. This is also complicated by the inventory overhaul in 2.4, which allows multiple inventory files. Any hack that you come up with can easily break in future Ansible versions, as the information you want is not part of the “guaranteed” callback plugin interface.
Thank you for your reply… Andrew