Updating Ansible hosts inventory dynamically

25 views
Skip to first unread message

Subhi Andrews

unread,
Feb 1, 2019, 2:09:41 PM2/1/19
to Ansible Project
We have our hosts inventory organized by environments. We tend to have alpha versions of software deployed in our test environment. Are there any thoughts on keeping the inventory dynamically updated if we decide to move a host between environment - say from test to dev or from dev to production etc. Are there any best practices and such around it?

Thank you.

Kai Stian Olstad

unread,
Feb 1, 2019, 2:26:32 PM2/1/19
to ansible...@googlegroups.com
You have information in the documentation about dynamic inventory
https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html

Some plugins is created
https://docs.ansible.com/ansible/latest/plugins/inventory.html

If non of them suite your need you probably need to create your own.

--
Kai Stian Olstad

Subhi Andrews

unread,
Feb 1, 2019, 3:14:41 PM2/1/19
to Ansible Project
Thank you, Kai. Will check it out.

So if we can write a script that generates inventory in json format, we can directly pass the script to the ansible-playbook command? Did I understand that correctly?

Regards,

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/SwwNRlEoqyY/unsubscribe.
To unsubscribe from this group and all its topics, 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/2c62a4977194d117f83ef0fdfbd6e650%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Feb 1, 2019, 3:51:57 PM2/1/19
to ansible...@googlegroups.com
On 01.02.2019 21:13, Subhi Andrews wrote:
> Thank you, Kai. Will check it out.
>
> So if we can write a script that generates inventory in json format, we
> can
> directly pass the script to the ansible-playbook command? Did I
> understand
> that correctly?

That is correct, if a inventory file doesn't have the execution bit set
Ansible will read the content, if the execution bit is set Ansible will
run the file.

The script need to return json and the format is described here together
with how to develop a plugin
https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages