Ansible/Group by Distribution
From charlesreid1
It is useful to group machines by distribution, and it is possible to define these groups without explicitly doing so in the inventory file.
The following example playbook uses a group_by keyword and sets the group by key to the operating system distribution.
- name: talk to all hosts just so we can learn about them
hosts: all
tasks:
- name: Classify hosts depending on their OS distribution
group_by:
key: os_{{ ansible_facts['distribution'] }}
# now just on the CentOS hosts...
- hosts: os_CentOS
gather_facts: False
tasks:
- # tasks that only happen on CentOS go here