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

Inventory - IP addresses missing from virtual machine interfaces #321

Closed
biganthony opened this issue Aug 26, 2020 · 6 comments · Fixed by #334
Closed

Inventory - IP addresses missing from virtual machine interfaces #321

biganthony opened this issue Aug 26, 2020 · 6 comments · Fixed by #334
Labels
bug Something isn't working help wanted Extra attention is needed PR Required

Comments

@biganthony
Copy link

ISSUE TYPE
  • Bug Report
SOFTWARE VERSIONS
Ansible:

ansible 2.9.11

Netbox:

2.9.1

Collection:

1.0.1

SUMMARY

When interfaces is set to TRUE the IP address array is empty for all VMs

STEPS TO REPRODUCE

set interfaces: True in inventory yml

plugin: netbox.netbox.nb_inventory
api_endpoint: http://netbox
validate_certs: True
config_context: False
services: True
interfaces: True
fetch_all: False
plurals: False

group_by:
  - role

query_filters:
  - cluster_id: 1

compose:
  netbox_vm_id: id
EXPECTED RESULTS
interfaces": [
  {
   "description": "",
   "enabled": true,
   "id": 4,
   "ip_addresses": [
       "List of IP objects": "Example"
    ],
   "mac_address": null,
   "mode": null,
   "mtu": null,
   "name": "ens18",
   "tagged_vlans": [],
   "tags": [],
   "untagged_vlan": null,
   "url": "http://netbox/api/virtualization/interfaces/4/",
   "virtual_machine": {
    "id": 13,
    "name": "VM NAME",
    "url": "http://i/api/virtualization/virtual-machines/13/"
   }
  }
 ]
ACTUAL RESULTS
interfaces": [
  {
   "description": "",
   "enabled": true,
   "id": 4,
   "ip_addresses": [],
   "mac_address": null,
   "mode": null,
   "mtu": null,
   "name": "ens18",
   "tagged_vlans": [],
   "tags": [],
   "untagged_vlan": null,
   "url": "http://netbox/api/virtualization/interfaces/4/",
   "virtual_machine": {
    "id": 13,
    "name": "VM NAME",
    "url": "http://i/api/virtualization/virtual-machines/13/"
   }
  }
 ]

Might be related to this.
netbox-community/netbox#4721
#319

@FragmentedPacket FragmentedPacket added bug Something isn't working help wanted Extra attention is needed PR Required labels Sep 3, 2020
@haxorof
Copy link
Contributor

haxorof commented Sep 8, 2020

Changes done in netbox-community/netbox#4721 causes this issue as I see it when looking into the code of nb_inventory.py

Within the selected lines (see links below) I replaced "interface" with "assigned_object_id":
https://github.com/netbox-community/ansible_modules/blob/v1.0.2/plugins/inventory/nb_inventory.py#L906
https://github.com/netbox-community/ansible_modules/blob/v1.0.2/plugins/inventory/nb_inventory.py#L918

Then I replaced ipaddress["interface"]["id"] with ipaddress["assigned_object_id"] in selected line:
https://github.com/netbox-community/ansible_modules/blob/v1.0.2/plugins/inventory/nb_inventory.py#L909

Those changes populate the ip_addresses as expected with v2.9. However to support NetBox v2.8 and v2.9+ requires a change here which I guess first look for assigned_object_id and if that is not found then try with interface as fallback to handle v2.8 and earlier.

Cheers!

haxorof added a commit to haxorof/ansible_modules that referenced this issue Sep 9, 2020
@haxorof
Copy link
Contributor

haxorof commented Sep 9, 2020

Did a PR #334 on this that I tested and where I try to address all NetBox versions

@haxorof
Copy link
Contributor

haxorof commented Sep 17, 2020

This fix is not correct after I discovered that assigned_object_id is not unique so assigned_object_type also must be considered now. :/ Will have a go at it again

@haxorof
Copy link
Contributor

haxorof commented Sep 17, 2020

Corrections done in PR #334

@biganthony
Copy link
Author

Thank you for your quick work @haxorof

@haxorof
Copy link
Contributor

haxorof commented Sep 17, 2020

Thank you for your quick work @haxorof

Happy to help! Especially when you suffer the non-backwards compatible changes in NetBox v2.9 yourself. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed PR Required
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants