Jinja templating doesn’t work in playbooks in that way. Lots of variable
constructs are actually parsed with jinja2, so you can do stuff like
- set_fact:
myvar: "{% if something %}this{% else %}that{% endif %}"
As Giovanni mentioned, there are numerous looping constructs for things
like task repetition. Playbooks are declarative, so it wouldn’t really be
right to build them from a template.
On 2 February 2015 at 12:34, Anand Buddhdev <[email protected]> wrote:
Hi Giovanni,
>
> Your suggestion works. But I think what I was trying to say is that
> Ansible's playbook syntax is mixed. Wouldn't it be cool if it were pure
> YAML, with Jinja templating? Then it would allow something like:
>
> - hosts: myhost
> tasks:
> - name: install packages
> yum:
> name:
> - tmux
> - screen
> {% if ansible_distribution_major_version == '6' %}
> - lsof
> {% endif %}
>
> Instead of inventing ansible-specific loops, we could just use the power
> of Jinja templating.
>
> On 2 February 2015 at 11:10, Giovanni Tirloni <[email protected]> wrote:
>
>> On Mon, 02 Feb 2015 10:58 +0100, Anand Buddhdev <[email protected]>
>> wrote:
>> > Hi Tom,
>> >
>> > I just tried the syntax you suggested.
>> >
>> > My very simple playbook is:
>> >
>> > - hosts: myhost
>> > tasks:
>> > - name: install packages
>> > yum:
>> > name:
>> > - screen
>> > - tmux
>> > state: installed
>> >
>>
>> - hosts: myhost
>> tasks:
>> - name: install packages
>> yum:
>> name: "{{ item }}"
>> state: latest
>> with_items:
>> - screen
>> - tmux
>>
>>
>> Useful reading:
>> http://docs.ansible.com/playbooks_loops.html
>>
>> Giovanni
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Ansible Project" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/ansible-project/dGJRlrohfmY/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, 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/1422871831.2610733.221884249.32774E87%40webmail.messagingengine.com
>> .
>> 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/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.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/CAAnNz0Onf2c6ngT08UTypz1mer6ty_QcBiDYkkMUUX33%3DAeeVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.