Ansible netbox_ip_address Assigning Primary ip4 Address

1,543 views
Skip to first unread message

Abhilash Reddy Ch

unread,
Aug 8, 2019, 6:47:29 PM8/8/19
to NetBox
Hello 

I am using Netbox 2.6.1 an duse ansible to create devices and IP addresses .
I am trying to create a Ip address for a device and make it as primary_ip4 and was able to get it working before and now I am not able to get it as a primary_ip4 (This might be specific to Ansible modules but not an issue with Netbox FYI)

ERROR:
"msg": {"primary_ip4": ["Related objects must be referenced by numeric ID or by dictionary of attributes. Received an unrecognized value:192.X.X.X

Code:
 name: Create IP address within Netbox with Primary IP
     netbox_ip_address:
       netbox_url: 
       netbox_token: 
       data:
         family: 4
         address: "{{ hostvars[item]['facter_ipaddress'] }}"
         interface:
           name: NIC1
           device: "{{item}}"
       state: present
     with_items: "{{groups.machines}}"

    netbox_device:
       netbox_url: 
       netbox_token: 
       data:
         name: "{{item}}"
         serial: "{{ hostvars[item]['SERIAL'] }}"
         primary_ip4: "{{ hostvars[item]['facter_ipaddress'] }}"

But now I am not even able to assign an IP address to a device using the playbook.Checking if someone has encountered the same issue ?

Thanks

Brian Candler

unread,
Aug 9, 2019, 6:41:48 AM8/9/19
to NetBox
You must use either:

    primary_ip4: NNN    # where NNN is the numeric ID (netbox primary key) of the IP address

or some combination of attributes which uniquely identifies the address, e.g. (untested)

    primary_ip4:
      address: "{{ hostvars[item]['facter_ipaddress'] }}"

Latter feature added in 2.6, details in #3077

Abhilash Reddy Ch

unread,
Aug 9, 2019, 1:38:05 PM8/9/19
to Brian Candler, NetBox
I tried that but getting a module error
ile \"/tmp/ansible_netbox_device_payload_jz1ij5wb/ansible_netbox_device_payload.zip/ansible/module_utils/net_tools/netbox/netbox_utils.py\", line 268, in build_query_params\nAttributeError: 'NoneType' object has no attribute 'intersection'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

I think it might not have been updated in the ansible module to support that functionality .I will keep working to find a fix 



--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/c6dc4c69-7285-4fbb-a08a-202096c44563%40googlegroups.com.

Brian Candler

unread,
Aug 9, 2019, 3:45:04 PM8/9/19
to NetBox
You appear to be missing
    with_items: "{{groups.machines}}"
from your final stanza.

Otherwise, you need to capture the API traffic generated by the Netbox module (e.g. using tcpdump) and show what it's sending.

Abhilash Reddy Ch

unread,
Aug 9, 2019, 3:54:03 PM8/9/19
to Brian Candler, NetBox
Hello Brian

Yeah I did include the groups.machines in the code .But it fails somehow.
That sounds about right to get analyze traffic let me check on it or see if there is any other way to update Primary IP using ansible

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages