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

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.

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.

You could accomplish this with script+add_host

  1. local_action script + register: output
  2. add_host: {{ item }} with_items: output.stdout

[...]

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

BR