Updating Ansible hosts inventory dynamically

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.

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.

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,

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