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

[Bug]: nb_inventory - Group by site_group does not work #1357

Open
aoforb opened this issue Nov 22, 2024 · 1 comment
Open

[Bug]: nb_inventory - Group by site_group does not work #1357

aoforb opened this issue Nov 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@aoforb
Copy link

aoforb commented Nov 22, 2024

Ansible NetBox Collection version

v3.20.0

Ansible version

ansible [core 2.17.3]
  config file = /repo/ansible/runner/project/ansible.cfg
  configured module search path = ['/repo/ansible/runner/project/library']
  ansible python module location = /repo/ansible/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /repo/ansible/runner/project/collections
  executable location = /repo/ansible/.venv/bin/ansible
  python version = 3.12.7 (main, Oct  1 2024, 08:52:11) [GCC 9.4.0] (/repo/ansible/.venv/bin/python3.12)
  jinja version = 3.1.4
  libyaml = True

NetBox version

v4.1.4

Python version

3.12

Steps to Reproduce

Our netbox groups have hyphens (-) but I have set force_valid_group_names = always in the ansible.cfg

Group by using site_group does not work

plugin: netbox.netbox.nb_inventory
api_endpoint: https://netbox
token: "1234"
validate_certs: false
config_context: true
group_by:
  - site_group
query_filters:
  - tenant: foo
  - role: foo-role
device_query_filters:
  - has_primary_ip: 'true'
group_names_raw: true

Group by using device_roles works fine.

Expected Behavior

Devices should be grouped by site group.

Observed Behavior

[WARNING]:  * Failed to parse /repo/ansible/runner/project/inventories/production/_foo/inventory/netbox_inventory.yml with ansible_collections.netbox.netbox.plugins.inventory.nb_inventory
plugin: 'InventoryModule' object has no attribute 'site_group_names'
  File "/repo/ansible/.venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/repo/ansible/runner/project/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 2179, in parse
    self.main()
  File "/repo/ansible/runner/project/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 2054, in main
    self._add_site_group_groups()
  File "/repo/ansible/runner/project/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 1884, in _add_site_group_groups
    self.site_group_names[site_id],
    ^^^^^^^^^^^^^^^^^^^^^
[WARNING]:  * Failed to parse /repo/ansible/runner/project/inventories/production/_foo/inventory/netbox_inventory.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
  File "/repo/ansible/.venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/repo/ansible/.venv/lib/python3.12/site-packages/ansible/plugins/inventory/yaml.py", line 113, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]: Unable to parse /repo/ansible/runner/project/inventories/production/_foo/inventory/netbox_inventory.yml as an inventory source
@aoforb aoforb added the bug Something isn't working label Nov 22, 2024
@aoforb
Copy link
Author

aoforb commented Nov 26, 2024

In the main() function ive added this.

        if (
            site_group_by in self.group_by
            or "site_group" in self.group_by                         <<<<< this bit
            or "location" in self.group_by
            or "region" in self.group_by
            or site_group_group_by in self.group_by
        ):
            self._add_site_groups()

It seems to work now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant