On Ansible 2.0.0.2 I am able to do this:
- include: "{{ansible_os_family | lower}}.yml"
Dne čtvrtek 17. října 2013 19:25:25 UTC+2 candlerb napsal(a):
>
> Using ansible 1.3.3, I am trying to structure my tasks like this:
>
> ==> 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.
>
> There is a tiny note at
> http://www.ansibleworks.com/docs/playbooks_roles.html which says:
> "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.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/07b16700-34a0-4e91-a0dc-d78d0b3cdf4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.