This will not work, since the hosts and roles must be known at the time the
playbook is read, so you can't do variable substitutions on those.

An alternative to this method is to have just the one role that includes
different task files based on the values of the system facts. See
https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_apt/tasks/main.ymlfor
example of how we limit the apt test to running on certain
distributions. This way, you can keep common tasks together while only
splitting out the distro-specific pieces.

This way, you could do the following:

- hosts: all
  roles:
  - { role: do_distro_stuff, target_os:
"{{ansible_distribution|lower}}{{ansible_lsb.major_release}}" }

and then in roles/do_distro_stuff/main.yml:

# includes for distro-version specific tasks
- include: 'ubuntu12.yml'
  when: target_os == 'ubuntu12'
- include: 'ubtunu14.yml'
  when: target_os == 'ubuntu14'
# ...
# and then do common tasks here

So you'd have to add new lines there when new distros come out, but that's
not something that occurs frequently so it's not a major concern.



On Wed, May 7, 2014 at 12:27 PM, Snyder, Chris <[email protected]> wrote:

>  I’m having a really hard time wrapping my head around how to organize my
> plays and roles with Ansible.
>
>
>
> What I have:
>
>                 I have multiple Linux distros I need to support with
> Ansible.  Each distro has different requirements which manifest themselves
> as different playbooks/roles/tasks/host groups.
>
>
>
> What I want (i.e. this is what my brain is telling me **SHOULD** be the
> correct solution for this type of situation. And yes, I **DO** have a
> programmer back ground):
>
>                 Call a single, general Ansible playbook that determines
> the specific distro/host on client host and then executes a more specific
> playbook and/or set of roles for my target host or host group.
>
>
>
> What I don’t want to do:
>
> -          I don’t want to have to programmatically determine the distro
> of my target host BEFORE calling Ansible so I can pass some OS-specific
> playbook name to Ansible on the command line for specific host or groups of
> hosts.
>
> -          I don’t want a SINGLE playbook which contains plays for all
> the OS’s I support – that’s just too large and unwieldy.
>
>
>
> Obviously, Ansible doesn’t parse variables as part of include statements,
> but IDEALLY, the following example is how I feel I should be solving my
> problem:
>
>
>
> - hosts: all
>
>   Tasks:
>
>     - name: Determine distrbution name and release
>
>       set_fact:
> myos="{{ansible_distribution|lower}}{{ansible_lsb.major_release}}"
>
>
>
>     - name: Group hosts by distro and release
>
>       action: group_by key={{myos}}
>
>
>
> - hosts: {{myos}}
>
>   Roles:
>
>     - {{myos}}
>
>
>
> So, how do other people solve/organize their solutions to problems similar
> to this?
>
>
>
> Thx
>
> Chris.
>
> --
> 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/BFD6B7398AEB474A9A28B39B9B5D00CB588A9696%40SRAexMBX05.sra.com<https://groups.google.com/d/msgid/ansible-project/BFD6B7398AEB474A9A28B39B9B5D00CB588A9696%40SRAexMBX05.sra.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/CAMFyvFhfajjOpe_7svNzND0t3qpp3%3DBBoAkYF4pgoQVrEBaakQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to