Using Netbox to set variables in my playbook

Hi all,

I currently use Ansible to generate all the network device configs and store them locally which works great. However, i currently have to store all my variables in a static .yml file.

Is it possible for ansible to hook into our netbox and pull the corect information needed to run the playbook? Essentially i want to get rid of the static vars file and use netbox instead.

Or do i need to go down the route of writing a python script that will write all the IP info to the vars file and then run ansible seperately?

I don’t mind either way but i would prefer to use ansible as it’s such a good product.

Many thanks in advance,
Marco

Hi,

I haven’t tried to use netbox that way, but since it does provide an API you should be able to use it with the uri module: http://docs.ansible.com/ansible/latest/uri_module.html

kind regards
Pshem

thank you so much for that. i’ve implimented it into my main.yml file and the GET request seems to work. I only know that because i don’t get any errors when i run the play book.

I do have another question though if that’s ok?

Even though i’ve pulled the json from the API i don’t know how i use it’s information in my .j2 file. What do i set the vars to be?