You can utilise an example described in Best Practices section with group_by
.
You would still have to modify the playbooks themselves to contain an appropriate hosts
declaration, for example:
nagios_centos.yml
:
---
- hosts: nagios_centos
# ... the rest of the play
nagios_ubuntu.yml
:
---
- hosts: nagios_ubuntu
# ... the rest of the play
Main playbook:
---
- hosts: all
tasks:
- group_by:
key: nagios_{{ ansible_os_family | lower }}
- import_playbook: nagios_centos.yml
- import_playbook: nagios_ubuntu.yml
Because of hosts
definition, only one of the playbooks would effectively run.