Hi Francisco

I tried this with v1.8.2 and it failed as your attempt, apparently not
expanding the variable. I thought this would have worked in previous
releases, but I could be wrong.

- include: "{{ ansible_distribution }}.yml"

In such a case, I sometimes do conditional includes within roles if I
really have to.

- include: MacOSX.yml
  when: ansible_distribution == 'MacOSX'

This has the side effect of showing the tasks therein as ‘skipped’ when the
conditional doesn’t match. So I keep them to a minimum and my roles
platform-specific. My preference is for small (thin) roles and verbose
playbooks, it makes for easier refactoring and reuse. In your playbooks,
you can use dynamic groups to apply platform oriented roles, as detailed
here:
http://docs.ansible.com/playbooks_best_practices.html#operating-system-and-distribution-variance

Regards
Tom
​

On 4 January 2015 at 22:28, Francisco Reyes <[email protected]> wrote:

>
> On Sunday, January 4, 2015 2:08:15 PM UTC-5, Tom Bamford wrote:
>>
>> The {{ ansible_os_family }} fact is usually set to the parent (or other
>> ancestor) distribution. For Ubuntu it will be set to “Debian”. You might
>> want to use {{ ansible_distribution }}
>>
>
> Tom,
> Thanks for the suggestion. That did not seem to help. It is as if the
> variable is not expanding.
>
> ERROR: file could not read: /roles/postgres/tasks/{{ ansible_distribution
> }}.yml
>
> Tried:
> ansible_os_family
> ansible_distribution
> id
>
> Made copy of the file as Ubuntu.yml and Debian.yml.. in case any option
> worked.
>
> For now, until I can figure the include out, going with this:
>
> - name: Handle install for Ubuntu
>   include: Ubuntu.yml
>   when: ansible_distribution == "Ubuntu"
>
> That did not even produce output.. which was what I was hoping for.. so if
> I can't figure out the include this would work.
>
> Will very likely still want to figure it out; specially if I use
> include_vars so likely will revisit this.
>
> All the Galaxy roles I saw did Ubuntu or Centos. Want to do one for Ubuntu
> and FreeBSD.. and later (as low priority) throw in Centos.
>
> I use Ansible for my clients so I like the idea of something I can use for
> most of my clients vs using one role per OS. Looked at existing roles in
> galaxy and they were not quite what I needed. Plus figure would be a good
> exercise for a first role for Galaxy.
>
> --
> 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/d502c6fc-cf0b-4855-bdaa-5449c54f4608%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d502c6fc-cf0b-4855-bdaa-5449c54f4608%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAAnNz0N%2BC17PyzKf12jruEDb2fg4ewB%3DJLB5MdwayEb6WkgaJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to