Home:ALL Converter>Ansible: Create a dynamic hostgroup based on host variables

Ansible: Create a dynamic hostgroup based on host variables

Ask Time:2022-11-11T00:31:17         Author:moritz

Json Formatter

Is it possible to auto create a host group based on manually defined host variables?

This is my inventory:

[webserver]
web1         ansible_host=192.168.20.1     production=False
web2         ansible_host=192.168.20.2     production=False
web3         ansible_host=192.168.20.3     production=True
web4         ansible_host=192.168.20.4     production=True
...

I want to have a dynamic hostgroup, e.g., webserver_production and use this as target.

Is there another way to do archive this? Thank you.

Author:moritz,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74392322/ansible-create-a-dynamic-hostgroup-based-on-host-variables
yy