# Using Netbox to set variables in my playbook

**URL:** <https://forum.ansible.com/t/using-netbox-to-set-variables-in-my-playbook/25456>\
**Category:** Ansible Project\
**Created:** [September 12, 2017, 6:57am UTC](https://forum.ansible.com/t/using-netbox-to-set-variables-in-my-playbook/25456 "2017-09-12T06:57:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Baldanza](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@Marco\_Baldanza](https://forum.ansible.com/u/Marco_Baldanza)\
**Post date:** [September 12, 2017, 6:57am UTC](https://forum.ansible.com/t/using-netbox-to-set-variables-in-my-playbook/25456/1 "2017-09-12T06:57:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [September 12, 2017, 7:56am UTC](https://forum.ansible.com/t/using-netbox-to-set-variables-in-my-playbook/25456/2 "2017-09-12T07:56:28Z")

</div>

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](http://docs.ansible.com/ansible/latest/uri_module.html)

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![Marco\_Baldanza](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@Marco\_Baldanza](https://forum.ansible.com/u/Marco_Baldanza)\
**Post date:** [September 12, 2017, 1:41pm UTC](https://forum.ansible.com/t/using-netbox-to-set-variables-in-my-playbook/25456/3 "2017-09-12T13:41:09Z")

</div>

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?
