From charlesreid1

Revision as of 19:16, 13 November 2018 by Admin (talk | contribs) (Created page with "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 us...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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