netbox-community / ansible_modules

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

[Feature]: Add ability to retrieve virtual cluster members from netbox inventory #369

Open kcbark opened 4 years ago

kcbark commented 4 years ago
ISSUE TYPE
SOFTWARE VERSIONS
Ansible:

2.9.13

Netbox:

2.9.7

Collection:

v1.0.0

SUMMARY

We need a way to populate virtual chassis members properties via playbook. But since virtual chassi members are excluded by the inventory we are unable to.

STEPS TO REPRODUCE

ansible-inventory -i inventory/netbox.yml --list does not list virtual chassi members.

EXPECTED RESULTS

Add a toggle for including virtual chassis when asking for devices from netbox as inventory.

ACTUAL RESULTS

Virtual chassi members are not included when asking for devices from netbox as inventory.

nahun commented 3 years ago

I gave this a try myself. @kcbark, could you try it out to see if this is what you were thinking? See here for the code: https://github.com/nahun/ansible_modules/blob/vc-members/plugins/inventory/nb_inventory.py.

Add the virtual_chassis_members: true option to your inventory file.

If its good, I'll fix the tests and create a PR.

kcbark commented 3 years ago

Nice!

I almost forgot about this. I had a local patch as well but forgot to publish it.

I will test and get back to you.

Thanks!

FragmentedPacket commented 3 years ago

Any update on this from either of y'all?

And Merry Christmas by the way! Obviously I'm sure y'all are busy with family stuff, but once the holidays are over with, let me know how this is going for y'all.

nahun commented 3 years ago

Happy Holidays!

I need to rebase my branch and get the pieces for testing added. I'll create a PR when ready.

Just FYI, the way I'm implementing this is another data lookup for all devices that are VC members (virtual_chassis_member=true filter). Since the user might be filtering the devices list, we can't depend on that existing lookup to get all VC members.

FragmentedPacket commented 3 years ago

I'd make sure to only do that extra call if query_filters is specified to address your point of it being filtered and missing things.

Thanks for your incoming work on this!

ryanmerolle commented 3 years ago

I stumbled upon this issue when I setup some existing firewalls in netbox to join a virtual cluster. IE firewall-a & firewall-b are now members of the firewall cluster.

I would normally handle these devices as 1 given normal cluster behavior, BUT in terms of backup or reboot workflows, its important that the netbox inventory handle these as 2 different devices. I mean the API returns them as 2 different devices. I believe that overall virtual_clusters should be handled better.

IE I think for completeness the following flags should be supported(some already are):