Ansible automation POST to Netbox API

1,300 views
Skip to first unread message

I_Broke_The_Internet

unread,
Oct 24, 2017, 1:51:49 PM10/24/17
to NetBox
I am trying to determine the best method of getting Ansible to post JSON to the Netbox API. Currently I can gather facts on a device and get JSON output but the object names do not match the object name requirements for Netbox. Is anyone already doing this and are there copyable examples to get this into Ansible automation? It seems like if I can't find a solution I'd need to build out some form of templating to change the object names to match the Netbox object name requirements.

Thanks in advance

I_Broke_The_Internet

unread,
Nov 8, 2017, 11:38:44 AM11/8/17
to NetBox
Crickets... anyone have any suggestions?

Max

unread,
Jan 12, 2018, 11:14:02 AM1/12/18
to NetBox
Hi!

Did you come up with something? I'm currently evaluating asset management software like netbox, and importing via ansible is definitely a feature I need. I'll start working on it next week probably, but I just wanted to hear if you've achieved any progress (so I could save myself some time ;) )

Greetings,
Max

Damien Garros

unread,
Jan 12, 2018, 2:13:20 PM1/12/18
to NetBox
Hi 

Not sure if I understood the question correctly but I was able to post data into Netbox with Ansible URI module

I'm doing a first call to get the Netbox object ID based on a name 


- name: Find device in Netbox
local_action:
module: uri
url: "https://{{ netbox_addr }}/api/dcim/devices?name={{ inventory_hostname }}"
method: GET
headers:
Authorization: "Token {{ netbox_token }}"
status_code: 200
validate_certs: no
register: device

And later on I access the device id with "{{ device.json.results[0].id }}"
inventory_hostname is the slug of the device i'm looking for.

I think it would be great to get some native ansible module to manage the Netbox object, do you know if someone has started that ?

hope this help,
Damien 

Max

unread,
Jan 25, 2018, 5:02:15 AM1/25/18
to NetBox
I think what he meant (at least from what I understood, and what I am currently doing) is gathering facts of a hosts (with ansible's setup module, for example), and POSTing the gathered facts into NetBox. The problem here is that there's no module that currently does that automatically, meaning if I want to use Ansible to import hosts into NetBox, I have to come up with something that translates the JSON of the gathered facts into a series of POST operations that have the correct syntax to fit the NetBox API.

I_Broke_The_Internet

unread,
Jan 30, 2018, 11:47:30 AM1/30/18
to NetBox
Hey Max,

How are you gathering facts and POSTing to NetBox? I am still struggling with this and can't seem to make any progress. Thanks!

Nerdy_Rutgers

unread,
Feb 22, 2020, 11:35:38 AM2/22/20
to NetBox
Have you gotten this to work? I would love to import from ansible into NetBox. 

Joe

unread,
Feb 23, 2020, 5:01:35 AM2/23/20
to NetBox
Why not using the ansible netbox inventory module?

spaynter

unread,
Nov 9, 2020, 3:02:12 PM11/9/20
to NetBox
Im doing this, feel free to message me and i could help, im using pyats and cli.parse to pull data to netbox, just doing this small scale at the mo.

details here 

spaynter

unread,
Nov 9, 2020, 3:02:26 PM11/9/20
to NetBox
Reply all
Reply to author
Forward
0 new messages