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

120 views
Skip to first unread message

Arpit Ghiya

unread,
Jul 1, 2016, 9:44:21 AM7/1/16
to Ansible Project
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.

Andrea Tartaglia

unread,
Jul 1, 2016, 9:47:49 AM7/1/16
to ansible...@googlegroups.com
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. 


A.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/10a773cc-94f5-4c2e-83b4-dcd7bf6ec1cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

jta...@ansible.com

unread,
Jul 1, 2016, 12:50:30 PM7/1/16
to Ansible Project
You could accomplish this with script+add_host

1) local_action script <inventoryscript> + register: output
2) add_host: {{ item }} with_items: output.stdout

Benjamin Redling

unread,
Jul 5, 2016, 8:33:13 AM7/5/16
to ansible...@googlegroups.com


On 07/01/2016 08:50, Arpit Ghiya wrote:

> 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?
[...]

http://docs.ansible.com/ansible/intro_dynamic_inventory.html
http://docs.ansible.com/ansible/developing_inventory.html

BR
Reply all
Reply to author
Forward
0 new messages