# Getting variable from a database

**URL:** <https://forum.ansible.com/t/getting-variable-from-a-database/13749>\
**Category:** Ansible Project\
**Created:** [October 23, 2013, 12:45pm UTC](https://forum.ansible.com/t/getting-variable-from-a-database/13749 "2013-10-23T12:45:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smain\_Kahlouch](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@Smain\_Kahlouch](https://forum.ansible.com/u/Smain_Kahlouch)\
**Post date:** [October 23, 2013, 12:45pm UTC](https://forum.ansible.com/t/getting-variable-from-a-database/13749/1 "2013-10-23T12:45:07Z")

</div>

Hello,

Well my question is pretty straight forward:  
Actually we have tons of information stored on a db and i would like to know if it’s possible to get those and pass them to ansible as hosts/groups vars ?

It’s currently a postgresql db but we’re planning to switch to redis or mongodb.  
It would be therefore easier to generate json data structures.

I’ve seen the following syntax in the ansible documentation :  
–extra-vars “@some\_file.json”

So the idea is to run the json generation before ansible execution.

Could please help me to figure out the best option ?  
Thanks

Regards,  
Smana

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [October 23, 2013, 1:00pm UTC](https://forum.ansible.com/t/getting-variable-from-a-database/13749/2 "2013-10-23T13:00:41Z")

</div>

Hello,

look at custom inventory scripts:  
[http://www.ansibleworks.com/docs/intro\_dynamic\_inventory.html](http://www.ansibleworks.com/docs/intro_dynamic_inventory.html)  
[http://www.ansibleworks.com/docs/developing\_inventory.html](http://www.ansibleworks.com/docs/developing_inventory.html)

Basically, you can write script,that will return values from your database as json and you are done.

David

---

<div class="post-metadata">

**Author:** ![Smain\_Kahlouch](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@Smain\_Kahlouch](https://forum.ansible.com/u/Smain_Kahlouch)\
**Post date:** [October 23, 2013, 1:40pm UTC](https://forum.ansible.com/t/getting-variable-from-a-database/13749/3 "2013-10-23T13:40:06Z")

</div>

Cool thank you David,

I’ll have a look at this doc.  
I should have search a bit more 😛

Regards,  
Smana
