==> roles/ntp_client/tasks/main.yml <==
- include: "{{ ansible_os_family }}.yml"
==> roles/ntp_client/tasks/Debian.yml <==
- action: apt pkg=ntp state=installed
- service: name=ntp state=started enabled=yes
==> roles/ntp_client/tasks/RedHat.yml <==
- yum: name=ntp state=installed
- service: name=ntpd state=started enabled=yes
It fails with:
ERROR: file not found: /root/ansible/roles/ntp_client/tasks/{{ansible_os_family}}.yml
I also tried:
- include: $ansible_os_family
- include: ${ansible_os_family}.yml
which give:
ERROR: file not found: /root/ansible/roles/ntp_client/tasks/$ansible_os_family
ERROR: file not found: /root/ansible/roles/ntp_client/tasks/${ansible_os_family}.yml
respectively.
What I am trying to avoid is this:
- include: Debian.yml
when: ansible_os_family == 'Debian'
- include: RedHat.yml
when: ansible_os_family == 'RedHat'
which works, but is tedious if I have to write it for every role, and it also gives lots of 'skipping' tasks when run.
"Note that you cannot do variable substitution when including one playbook inside another."
which maybe applies to tasks/roles too - this isn't clear to me.
I could of course define distinct roles called, say:
roles/ntp_client_Debian
roles/ntp_client_RedHat
but to avoid conditionally including them, I would have to make different playbooks for Debian-based hosts and RedHat-based hosts.
Any other suggestions for how to achieve what I want here?
Thanks,
Brian.