Azure - Use Keyed Groups

Populate groups within a dynamic inventory of hosts deployed on Azure using keyed groups.

Keyed groups offer another way to define and populate groups within a dynamic inventory. Instead of specifying the group name, keyed groups base the group name on a host variable’s value, and group membership is determined by the existence of the host variable. Because of this, a single keyed group can replace both conditional groups we previously created.

Using the os_profile.system host variable to define a keyed group will create two groups: linux and windows. The keyed group then populates the group memberships based on all the hosts that match the same value. If a new Linux VM is deployed, the group membership would dynamically update to two hosts.

A new group would be dynamically created and populated based on the os_profile.system host variable if a new system type were deployed.

Conditional groups make the group memberships dynamic, but keyed groups make the groups and group memberships dynamic.

You will replace the conditional groups with a keyed group using the os_profile.system key. Review the lines 6-7 of the hosts_azure_rm.yml below:

Get hands-on with 1000+ tech skills courses.