# Running Ansible playbook without an inventory file (use other source for getting inventory)

**URL:** <https://forum.ansible.com/t/running-ansible-playbook-without-an-inventory-file-use-other-source-for-getting-inventory/21904>\
**Category:** Ansible Project\
**Created:** [July 1, 2016, 6:50am UTC](https://forum.ansible.com/t/running-ansible-playbook-without-an-inventory-file-use-other-source-for-getting-inventory/21904 "2016-07-01T06:50:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arpit\_Ghiya](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@Arpit\_Ghiya](https://forum.ansible.com/u/Arpit_Ghiya)\
**Post date:** [July 1, 2016, 6:50am UTC](https://forum.ansible.com/t/running-ansible-playbook-without-an-inventory-file-use-other-source-for-getting-inventory/21904/1 "2016-07-01T06:50:36Z")

</div>

Hello  
We are currently in a process to switch from our current legacy systems to Ansible for server provisioning and deployment. All of our server details are stored in ruby configuration files [.rb], which is obviously our server inventory right now.

Now, we are planning to use the same config files as input to ansible-playbook for deployment. I can write a script which will read my ruby file and create a ansible style inventory file on the run time. Now, it is possible for Ansible to read the inventory dynamically after the execution starts?

Eg:  
**Step 1** : Call Ansible-Playbook (with a variable to define my environment; eg: qa/uat etc)  
**Step 2** ; I call my custom script which in turn reads ruby config file for that particular environment and generates the Ansible inventory  
**Step 3** : Ansible now reads the inventory and proceeds with the remaining tasks from the playbook.

P.S. The reason we are a bit reserved about creating inventory in Ansible on the first place is because we don’t want redundant information. The ruby config files act as a Golden Source for server details for many other systems as well. If we replicate them in Ansible inventory - we will end up managing them at two places.

---

<div class="post-metadata">

**Author:** ![Shaps](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shaps/32/1356_2.png) [@Shaps](https://forum.ansible.com/u/Shaps)\
**Post date:** [July 1, 2016, 1:47pm UTC](https://forum.ansible.com/t/running-ansible-playbook-without-an-inventory-file-use-other-source-for-getting-inventory/21904/2 "2016-07-01T13:47:37Z")

</div>

Hi,

I think instead writing a script that then writes an inventory file, just write a dynamic inventory and pass that as inventory file to ansible. I believe it will make your life easier in the long run.

---

<div class="post-metadata">

**Author:** ![jtanner](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@jtanner](https://forum.ansible.com/u/jtanner)\
**Post date:** [July 1, 2016, 4:50pm UTC](https://forum.ansible.com/t/running-ansible-playbook-without-an-inventory-file-use-other-source-for-getting-inventory/21904/3 "2016-07-01T16:50:30Z")

</div>

You could accomplish this with script+add\_host

1. local\_action script + register: output
2. add\_host: {{ item }} with\_items: output.stdout

---

<div class="post-metadata">

**Author:** ![Benjamin\_Redling](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@Benjamin\_Redling](https://forum.ansible.com/u/Benjamin_Redling)\
**Post date:** [July 5, 2016, 12:33pm UTC](https://forum.ansible.com/t/running-ansible-playbook-without-an-inventory-file-use-other-source-for-getting-inventory/21904/4 "2016-07-05T12:33:02Z")

</div>

[...]

[http://docs.ansible.com/ansible/intro\_dynamic\_inventory.html](http://docs.ansible.com/ansible/intro_dynamic_inventory.html)  
[http://docs.ansible.com/ansible/developing\_inventory.html](http://docs.ansible.com/ansible/developing_inventory.html)

BR
