can't create new element

189 views
Skip to first unread message

Sambiga

unread,
Apr 6, 2021, 12:49:25 PM4/6/21
to NetBox
hello all,
I am not good in english so I hope you will understand me.
I am using ansible to interact with netbox and am having some issue :
when i try to create an ip address in netbox from ansible I get message  that the ip address has been created but when I go back to netbox the ip address is not there.

task ansible:
    - name: Getting prefix
      delegate_to: localhost
      netbox.netbox.netbox_ip_address:
            netbox_url: URL
            netbox_token: TOKEN
            validate_certs: no
            data:
              address: 10.10.10.254
            state: present

here is the fedback from ansible :
    "changed": true,
    "diff": {
        "after": {
            "state": "present"
        },
        "before": {
            "state": "absent"
        }
    },
    "invocation": {
        "module_args": {
            "data": {
                "address": "10.10.10.254",
                "assigned_object": null,
                "custom_fields": null,
                "description": null,
                "dns_name": null,
                "family": null,
                "interface": null,
                "nat_inside": null,
                "prefix": null,
                "role": null,
                "status": null,
                "tags": null,
                "tenant": null,
                "vrf": null
            },
            "netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "netbox_url": "url",
            "query_params": null,
            "state": "present",
            "validate_certs": false
        }
    },
    "ip_address": {
        "count": 1,
        "next": null,
        "previous": null,
        "results": [
            2
        ]
    },
    "msg": "ip_address 10.10.10.254/32 created"
}

Also when i try to creat the ip address using CURL it doesn't work :

curl request : curl -k -s --location --request PUT 'http://localhost/api/ipam/aggregates/?address=10.10.10.254/32' --header "Authorization: token $NETBOX_TOKEN" --header 'Content-Type: application/json'

output :  {"non_field_errors":["Expected a list of items but got type \"dict\"."]}

can anyone help me out ?

Brian Candler

unread,
Apr 6, 2021, 1:58:17 PM4/6/21
to NetBox
>     "msg": "ip_address 10.10.10.254/32 created"

I don't know if that message comes from Ansible or Netbox.  I suggest you run tcpdump on the connection between ansible and netbox to see what it's actually sending (if it's HTTPS then use tcpdump on the connection between your frontend Apache or Nginx, and the gunicorn process).  If there's an error from Netbox you should be able to see it.

> curl request : curl -k -s --location --request PUT 'http://localhost/api/ipam/aggregates/?address=10.10.10.254/32' --header "Authorization: token $NETBOX_TOKEN" --header 'Content-Type: application/json'
> output :  {"non_field_errors":["Expected a list of items but got type \"dict\"."]}

Lots of things are wrong with that curl command:

1. Aggregates are not IP addresses.  The endpoint you want is /api/ipam/ip-addresses/
2. You need to use POST, not PUT, to create a new object
3. You need to include a JSON body in the POST request - you cannot supply the address as a query parameter

Reply all
Reply to author
Forward
0 new messages