You can use "group_by" to avoid repeated conditionals.

Select the hosts where something is true and apply roles/tasks to the
dynamically created group.


On Thu, Jun 12, 2014 at 10:25 AM, Oliver Heinz <
oliver.heinz....@googlemail.com> wrote:

> Thanks for pointing this out.
>
> So
>   tasks:
>   - include:
> "{{ansible_distribution}}{{ansible_distribution_major_version}}.yml"
>
> would expand to
>
>   tasks:
>   - include: Debian6.yml
>     when: ansible_distribution == Debian AND
> ansible_distribution_major_version == 6
>
>   - include: Debian7.yml
>     when: ansible_distribution == Debian AND
> ansible_distribution_major_version == 7
>
>   - include: RedHat5.yml
>     when: ansible_distribution == RedHat AND
> ansible_distribution_major_version == 5
>
>   - include: RedHat6.yml
>     when: ansible_distribution == RedHat AND
> ansible_distribution_major_version == 6
> [...]
>
>
> This is definitely better than putting everything into one file. But I'd
> still like it much more when the single include + fact var worked - this is
> the way that is recommended for working with config templates/files so it
> feels somewhat wrong that it does not work with task includes.
>
>
> Am Donnerstag, 12. Juni 2014 15:29:40 UTC+2 schrieb Serge van Ginderachter:
>
>> This is  not possible, as the parsing of the playbooks happens before
>> anything else.
>>
>> The best practice here is to use conditionals on and variables within
>> specific tasks.
>>
>>
>> On 12 June 2014 15:22, Oliver Heinz <oliver.h...@googlemail.com> wrote:
>>
>>> Hi all,
>>>
>>> I cannot use facts for include variables. I think it's because the yaml
>>> syntax checker fails (as they don't exits at that time):
>>>
>>> My test play:
>>> ---
>>> - hosts: localhost
>>>   gather_facts: true
>>>   tasks:
>>>   - include: "{{ansible_distribution}}{{ansible_distribution_major_
>>> version}}.yml"
>>>
>>> $ansible-playbook -i hosts -l localhost -C playbooks/test.yml
>>> ERROR: file could not read: /home/heinzoliver/ansible/
>>> branches/heinzoliver/playbooks/{{ansible_distribution}}{{ansible_
>>> distribution_major_version}}.yml
>>>
>>> => it should be /home/heinzoliver/ansible/branches/heinzoliver/
>>> playbooks/Debian7.yml
>>>
>>> My goal is to put the tasks that differ between the distiributions in
>>> seperate task files to avoid having lot's of when-clauses or completely
>>> seperated roles for things that are 90% the same and differ 10% between
>>> dists/dist-versions.
>>> Is there any chance that the facts can be gathered before doing the rest
>>> of the syntax checking? Is it possible to disable the checks? Or am I'm on
>>> the wrong track at all?
>>>
>>> TIA,
>>> Oliver
>>>
>>>
>>>
>>>
>>>
>>>
>>>  --
>>> 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 ansible-proje...@googlegroups.com.
>>> To post to this group, send email to ansible...@googlegroups.com.
>>>
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/ansible-project/31ff684a-330a-4c05-99ba-
>>> d49c73a0b8af%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/31ff684a-330a-4c05-99ba-d49c73a0b8af%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 ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f0e86faf-dfd8-47a0-9c2d-859bec6a9f6d%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f0e86faf-dfd8-47a0-9c2d-859bec6a9f6d%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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgyn%3D%3D3SZParDhoRSstHt60LcPMQwzLpeRF9JR%2BGqjiQkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to