I want to build ansible inventory and assign hosts to respective groups based on the values gathered from Clients.

Eg: Information of all the clients and their respective group will be pushed to ansible server every night in the below format.

File Format


From the content of above file i need to create ansible inventory

closed as unclear what you're asking by Kiwy, Romeo Ninov, Jeff Schaller, G-Man, dr01 May 17 '18 at 10:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • what have you tried ? what is the expected output ? Ansible work with Yaml put can accept other format. – Kiwy May 16 '18 at 12:47

You have several options you can use here.

1) Write a script which takes those files and generates the "inventory file" format that ansible uses. Then run that script on a cron job or something after all the uploads take place.

2) Write a script which generates output format complying with the Ansible inventory JSON format, and use it as such: https://docs.ansible.com/ansible/2.5/plugins/inventory/script.html

3) Use the add_host task type as the very first task in your playbook (with a localhost host) with a loop to add the hosts.

  name: "{{ item.hostname }}"
  groups: "{{ item.group }}"
with_items: "{{ somehow inject your list here }}"

Not the answer you're looking for? Browse other questions tagged or ask your own question.