netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
327 stars 208 forks source link

Creating group of groups with nb_inventory #468

Open kr3ator opened 3 years ago

kr3ator commented 3 years ago
ISSUE TYPE
SOFTWARE VERSIONS
Ansible:

2.10.5

Netbox:

2.10.4

Collection:

3.0.0 (same with 2.1.0)

SUMMARY

Groups of groups are created in one environment but not in others

STEPS TO REPRODUCE
  1. Define groups inside inventory YAML:
groups:
  fabric:
    routers:
    spines:
    leafs:
  routers: device_role.name == 'network_router'
  spines: device_role.name == 'network_spine'
  leafs: device_role.name == 'network_leaf'
  1. Run ansible-inventory --graph and check created groups and hosts within them.
EXPECTED RESULTS

Four groups created: leafs, spines, routers, fabric Leafs, spines and routers list the device names. Fabric group has leafs, spines and routers groups as children (optionally list of all devices in these groups).

ACTUAL RESULTS

In some environments I get the expected behaviour where the fabric group has all the devices that are in leafs, spines and routers groups. But on other systems the fabric group is not created.

I have couple of environments where I run my playbooks, in all of them I use venv with consistent Ansible, Netbox and Collection versions and exactly the same host definition YAMLs.

The only difference is in the underlaying OS and Python version. System on which I get the expected result is a WSL Ubuntu with Python 3.8.5

Other systems on which I don't get the fabric group are Centos with Python 3.6.8.

I'd apprecieate any help.

ryanmerolle commented 2 years ago

I use the following to create the groups

group_by:
  - role

I have to look at if you can use the groups to define other groups created by group_by

I will try to take a look today.

ryanmerolle commented 2 years ago

@k0ste who is that directed at?

k0ste commented 2 years ago

@ryanmerolle sorry, I was missed out that this is not that https://github.com/netbox-community/ansible_modules/discussions/668 thread 😐