Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructured inventory in gql_inventory #323

Merged
merged 2 commits into from
Mar 28, 2024

Conversation

itdependsnetworks
Copy link
Contributor

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 itdependsnetworks changed the title Fix constructured inventory in gql_inventory Add constructured inventory in gql_inventory Mar 24, 2024
@itdependsnetworks
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor

@joewesch joewesch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to approve this, but I realize that we have 0 tests for the gql_inventory so we should create an issue to get some added if we don't add a couple tests to this PR.

@joewesch joewesch merged commit 00eac3b into nautobot:develop Mar 28, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants