nautobot / nautobot-ansible

Ansible Collection for managing Nautobot Data
https://nautobot-ansible.readthedocs.io/en/latest/
GNU General Public License v3.0
40 stars 31 forks source link

Add constructured inventory in gql_inventory #323

Closed itdependsnetworks closed 3 months ago

itdependsnetworks commented 3 months ago

It is worth nothing that in my testing extends_documentation_fragment is impacting to the inventory successfully working, meaning if the below is removed it will fail with an error on the get_options calls to strict or compose.

extends_documentation_fragment:
  - constructed
  - inventory_cache
itdependsnetworks commented 3 months ago

here is the error without extends_documentation_fragment set.

toml declined parsing /github/cookbook/inventory.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /github/cookbook/inventory.yml with script plugin: problem running /github/cookbook/inventory.yml --list ([Errno 8] Exec format error: '/github/cookbook/inventory.yml')
  File "/usr/local/lib/python3.11/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/lib/python3.11/site-packages/ansible/plugins/inventory/script.py", line 150, in parse
    raise AnsibleParserError(to_native(e))
[WARNING]:  * Failed to parse /github/cookbook/inventory.yml with auto plugin: 'Requested entry (plugin_type: inventory plugin: ansible_collections.networktocode.nautobot.plugins.inventory.gql_inventory setting: strict ) was not defined in
configuration.'
  File "/usr/local/lib/python3.11/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/lib/python3.11/site-packages/ansible/plugins/inventory/auto.py", line 59, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/root/.ansible/collections/ansible_collections/networktocode/nautobot/plugins/inventory/gql_inventory.py", line 431, in parse
    self.main()
  File "/root/.ansible/collections/ansible_collections/networktocode/nautobot/plugins/inventory/gql_inventory.py", line 396, in main
    strict = self.get_option("strict")
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ansible/plugins/__init__.py", line 77, in get_option
    raise KeyError(to_native(e))
itdependsnetworks commented 3 months ago

The crux of it is that at some point (set_options -> get_plugin_options -> get_configuration_definitions) this gets called which basically the ansible doc values and sets the options. Already down a far enough rabbit hole, but if want to look into it in the future, at least documented where I left off.

joewesch commented 3 months ago

Yup, you need to extend the doc fragment according to the docs: https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#constructed-features