How is a subgroup represented within a parent group in an Ansible inventory file?

QuestionsQuestions8 SkillsProAnsible Groups InventoryAug, 05 2025
0161

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:

  • webservers and database are parent groups.
  • The all:children group includes both webservers and database as 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.

0 Comments

no data
Be the first to share your comment!