nautobot / nautobot-ansible

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

Inventory with virtual_chassis_name doesn't work #145

Closed gerardocastaldo closed 2 years ago

gerardocastaldo commented 2 years ago
ISSUE TYPE
SOFTWARE VERSIONS
pynautobot

pynautobot==1.1.2

Ansible:

root@3be97d18304b:~/ansible_project# ansible --version ansible [core 2.12.6] config file = /root/ansible_project/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.10/site-packages/ansible ansible collection location = /root/ansible_project/collections executable location = /usr/local/bin/ansible python version = 3.10.5 (main, Jun 7 2022, 19:11:36) [GCC 8.3.0] jinja version = 3.1.2 libyaml = True

Nautobot:

v1.3.2

Collection:

Collection Version


amazon.aws 2.3.0
ansible.netcommon 2.6.1
ansible.posix 1.4.0
ansible.utils 2.6.1
ansible.windows 1.10.0 arista.eos 3.1.0
awx.awx 19.4.0 azure.azcollection 1.13.0 check_point.mgmt 2.3.0
chocolatey.chocolatey 1.2.0
cisco.aci 2.2.0
cisco.asa 2.1.0
cisco.dnac 6.4.0
cisco.intersight 1.0.19 cisco.ios 2.8.1
cisco.iosxr 2.9.0
cisco.ise 1.2.1
cisco.meraki 2.6.2
cisco.mso 1.4.0
cisco.nso 1.0.3
cisco.nxos 2.9.1
cisco.ucs 1.8.0
cloud.common 2.1.1
cloudscale_ch.cloud 2.2.2
community.aws 2.5.0
community.azure 1.1.0
community.ciscosmb 1.0.5
community.crypto 2.3.2
community.digitalocean 1.19.0 community.dns 2.2.0
community.docker 2.6.0
community.fortios 1.0.0
community.general 4.8.2
community.google 1.0.0
community.grafana 1.4.0
community.hashi_vault 2.5.0
community.hrobot 1.4.0
community.kubernetes 2.0.1
community.kubevirt 1.0.0
community.libvirt 1.1.0
community.mongodb 1.4.0
community.mysql 2.3.8
community.network 3.3.0
community.okd 2.2.0
community.postgresql 1.7.4
community.proxysql 1.4.0
community.rabbitmq 1.2.1
community.routeros 2.1.0
community.sap 1.0.0
community.sap_libs 1.1.0
community.skydive 1.0.0
community.sops 1.2.2
community.vmware 1.18.0 community.windows 1.10.0 community.zabbix 1.7.0
containers.podman 1.9.3
cyberark.conjur 1.1.0
cyberark.pas 1.0.14 dellemc.enterprise_sonic 1.1.1
dellemc.openmanage 4.4.0
dellemc.os10 1.1.1
dellemc.os6 1.0.7
dellemc.os9 1.0.4
f5networks.f5_modules 1.17.0 fortinet.fortimanager 2.1.5
fortinet.fortios 2.1.6
frr.frr 1.0.4
gluster.gluster 1.0.2
google.cloud 1.0.2
hetzner.hcloud 1.6.0
hpe.nimble 1.1.4
ibm.qradar 1.0.3
infinidat.infinibox 1.3.3
infoblox.nios_modules 1.2.2
inspur.sm 1.3.0
junipernetworks.junos 2.10.0 kubernetes.core 2.3.1
mellanox.onyx 1.0.0
netapp.aws 21.7.0 netapp.azure 21.10.0 netapp.cloudmanager 21.17.0 netapp.elementsw 21.7.0 netapp.ontap 21.19.1 netapp.storagegrid 21.10.0 netapp.um_info 21.8.0 netapp_eseries.santricity 1.3.0
netbox.netbox 3.7.1
ngine_io.cloudstack 2.2.4
ngine_io.exoscale 1.0.0
ngine_io.vultr 1.1.1
openstack.cloud 1.8.0
openvswitch.openvswitch 2.1.0
ovirt.ovirt 1.6.6
purestorage.flasharray 1.13.0 purestorage.flashblade 1.9.0
sensu.sensu_go 1.13.1 servicenow.servicenow 1.0.6
splunk.es 1.0.2
t_systems_mms.icinga_director 1.29.0 theforeman.foreman 2.2.0
vmware.vmware_rest 2.1.5
vyos.vyos 2.8.0
wti.remote 1.0.3
ansible.netcommon 3.0.1
ansible.utils 2.6.1
arista.cvp 3.3.1
cisco.ios 3.1.0
cisco.nxos 3.0.0
community.general 5.1.0
community.network 4.0.1
networktocode.nautobot 3.4.1

SUMMARY

I need to create an inventory ignoring the virtual chassis name. I setted virtual_chassis_name option to false but the output is identical. I resolved the problem but i would to ask if my solution is correct and if it's possible merging the solution in next release. I haven't experience about github merge procedure.

STEPS TO REPRODUCE

Configure two device in virtual chassis. Configure inventory file with virtual_chassis_name to false. Run ansible-inventory --graph or similar.

" inventory.yaml

plugin: networktocode.nautobot.inventory
validate_certs: False
virtual_chassis_name: no
services: no
fetch_all: false
cache: yes
cache_timeout: 3600
compose:
  area: (display | split('-'))[1]
group_by:
  - device_roles
  - platforms
  - sites
  - tags
query_filters:
  - role: network
EXPECTED RESULTS

I expected list with specific members.

ACTUAL RESULTS

The inventory contains always the virtual chassis primary device.

I resolved the problem changing the main function in plugins/inventory/inventory.py

from

       for host in chain(self.devices_list, self.vms_list):

            virtual_chassis_master = self._get_host_virtual_chassis_master(host)
            if virtual_chassis_master is not None and virtual_chassis_master != host["id"]:
                # Device is part of a virtual chassis, but is not the master
                continue

to

       for host in chain(self.devices_list, self.vms_list):

            virtual_chassis_master = self._get_host_virtual_chassis_master(host)
            if self.virtual_chassis_name and virtual_chassis_master is not None and virtual_chassis_master != host["id"]:
                # Device is part of a virtual chassis, but is not the master
                continue
gerardocastaldo commented 2 years ago

Sorry me, I omitted a details. To reproduce the problem one member need to set like primary.

jvanderaa commented 2 years ago

As I read through what is described, I believe that this is working as intended, but there may be something in the intention that is not being captured.

On an inventory, the purpose is to provide the information needed to connect to the device. In the case of a virtual-chassis within the paradigm, you only connect to the primary host. The secondary host(s) all act as part of the primary unit. This I have seen to be the case with Cisco VSS pairs, Cisco switch stacks (Catalyst), and Juniper multiple-chassis units.

The notes for the variable virtual_chassis_name are:

When a device is part of a virtual chassis, use the virtual chassis name as the Ansible inventory hostname

Let's converse through what you are looking to accomplish on this.

gerardocastaldo commented 2 years ago

Hi, I understand what you mean and I probably misunderstood the guide. I need to retrieve member information on both the master and slave node but I probably need to use a gql query for this particular case.

Thanks for your suport.

jvanderaa commented 2 years ago

More so this should exist within the playbooks with data rather than in the inventory. For the inventory purposes, connecting to devices, you would only need the one node in the inventory, not the entire stack.