Sure, but that's exactly the thing I would like to deal with within a role,
within a role however you can't perform the 'include' you stated in your
post as "ansible_os_family" doesn't seem to evaluate.
Op maandag 23 juni 2014 20:33:42 UTC+2 schreef Michael DeHaan:
>
> Most all ansible modules already abstract out OS details.
>
> Package managers we want you to know - not only do package names change,
> but the way you interact with those packages change - think of how
> different Apache is between Ubuntu and CentOS for instance.
>
> You can do things like
> - include: "{{ ansible_os_family }}.yml"
>
> And you can also do things like use "include_vars" with similar tricks
> where you want to maintain differences.
>
> In most cases you'll only differ by variables except having a few tasks
> with "when" statements on them keying off the OS - which will also minimize
> task duplication.
>
>
>
>
> On Mon, Jun 23, 2014 at 1:05 PM, Nico K. <[email protected] <javascript:>
> > wrote:
>
>> Hi,
>>
>> So I've been scavenging through a lot of posts to figure out how to deal
>> with heterogeneous environments.
>> The two approaches that I see most are either using "group_by" or using
>> "when".
>>
>> For example:
>>
>> site.yml:
>> - name: whatever
>> tasks:
>> - group_by: key={{ansible_os_family}
>>
>> - hosts: Debian
>> roles:
>> - role: rolename-debian
>>
>> - hosts: Darwin
>> roles:
>> - role: rolename-darwin
>>
>> My problem with this approach is that you are saying that a role is "OS"
>> specific, even though it's not. Perhaps this has to do with my definition
>> of role, but as I see it a 'role' is a task that any given node can perform.
>> I should be able to assign the 'role' 'nginx' to a variety of hosts, how
>> those hosts then implement that role should be defined within the 'role'
>> definition.
>>
>> Now supposedly you can do this using the 'when' conditional statement,
>> you would then end up with something like:
>>
>> roles/myRole/tasks
>>
>> - include: apt.yml
>> when: ansible_os_family == "Debian"
>>
>> - include: brew.yml
>> when ansible_os_family == "Darwin"
>>
>> However this is rather chatty, especially when these files include files
>> of there own. And with chatty I mean every task, even when the 'when'
>> clause is not matched is being shown, now you can set 'show_skipped_hosts"
>> in the ansible configuration, however this still shows the headers of tasks
>> that are (not) being processed.
>>
>> Should I be dealing with this in a different fashion?
>> What I'm trying to accomplish is having a playbook that installs a
>> package on a bunch of machines (running differents OS's), then configure
>> that package based on the OS and configure the service accordingly.
>>
>> IMHO the latter approach is the way to go, however the 'chattyness' is
>> killing my operators.
>>
>> Thanks a lot for sharing your insights.
>>
>> Best regards.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/61f300f9-bb1e-4ef3-89a3-c81637202fb5%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/61f300f9-bb1e-4ef3-89a3-c81637202fb5%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/1cc12aef-2290-4769-bff5-4129b6e9aaaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.