Re: [ansible-project] How to template tasks file?

26 views
Skip to first unread message

Matt Martz

unread,
Nov 23, 2015, 12:04:52 PM11/23/15
to ansible...@googlegroups.com
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.


On Mon, Nov 23, 2015 at 10:03 AM, Pavel Vaysberg <pvay...@hubcitymedia.com> 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 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/b7465af7-6ca9-48dc-bb2f-056d176617af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages