In an Ansible inventory file, a subgroup can be represented by defining it under a parent group using a colon : to indicate the hierarchy. Here’s an example of how to structure this:
[webservers]
localhost ansible_connection=local
[database]
db1 ansible_connection=local
[all:children]
webservers
database
In this example:
webserversanddatabaseare parent groups.- The
all:childrengroup includes bothwebserversanddatabaseas subgroups.
You can also define variables specific to a subgroup by adding them under the subgroup definition:
[webservers:vars]
http_port=80
[database:vars]
db_port=5432
This way, you can manage configurations and variables effectively within your Ansible inventory.
