You cannot template a whole task file.

What you need is to put a with_indexed_items on each of those lineinfile
tasks, as opposed to using a jinja for loop around them.

http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-a-list-with-an-index

On Mon, Nov 23, 2015 at 10:03 AM, Pavel Vaysberg <[email protected]
> wrote:

> Hey all, I am trying to repeat several tasks depending on how many servers
> I have in a certain group. Here is the code:
>
> {% for machine in groups['cluster_nodes'] %}
> - lineinfile: dest={{domain_home}}/servers/soa_server{{ loop.index + 1
> }}/security/boot.properties create=yes line="username={{wls_user}}"
> - lineinfile: dest={{domain_home}}/servers/soa_server{{ loop.index + 1
> }}/security/boot.properties create=yes line="password={{wls_pw}}"
>
> - lineinfile: dest={{domain_home}}/servers/oim_server{{ loop.index +
> 1}}/security/boot.properties create=yes line="username={{wls_user}}"
> - lineinfile: dest={{domain_home}}/servers/oim_server{{ loop.index +
> 1}}/security/boot.properties create=yes line="password={{wls_pw}}"
> {% endfor %}
>
> However, when I try to do this I get the following error:
>
> ERROR: Syntax Error while loading YAML script, /.../main.yml
>
> Note: The error may actually appear before this position: line 171, column
> 2
>
>
>
> {% for machine in groups['cluster_nodes'] %}
>
> ^
>
> Not sure what I am doing wrong, as I thought every file in ansible gets
> put through the Jinja2 templating language..
>
> --
> 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/b7465af7-6ca9-48dc-bb2f-056d176617af%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b7465af7-6ca9-48dc-bb2f-056d176617af%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

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

Reply via email to