You forgot to include condition in the tasks, like for example: 

- name: Template to 1st server.xml
  template: src=server.xml.j2 dest=/var/opt/tomcat_1/conf/server.xml 
owner=tomcat7 group=nogroup mode=0600
  when: port == "5000"
 
- name: Template to 2nd server.xml
  template: src=server.xml.j2 dest=/var/opt/tomcat_2/conf/server.xml 
owner=tomcat7 group=nogroup mode=0600
  when: port == "5001"

otherwise each will get executed on each run, of course.

On Thursday, July 30, 2015 at 4:23:41 AM UTC+10, Roger Sherman wrote:
>
> I have a group of hosts that have two tomcat instances on them, and I need 
> the server.xml to have different values in each instance. Initially, I 
> tried to write a jinja2 loop into a template, which I bailed on when 
> someone in the IRC channel pointed out parameterizing the role (from 
> http://docs.ansible.com/ansible/playbooks_roles.html - there's not a 
> direct anchor, so I'll quote):
>
> Also, should you wish to parameterize roles, by adding variables, you can 
>> do so, like this:
>
> - hosts: webservers
> roles:
> - common
> - { role: foo_app_instance, dir: '/opt/a', port: 5000 } 
> - { role: foo_app_instance, dir: '/opt/b', port: 5001 } 
>
>  But when I try the above, both server.xml's end up with the same value. 
> It looks like each subsequent pass through the role puts it's value in both 
> directories, so after the second time it runs, both server.xml's have the 
> second value. I pastebinned my playbook, role, and the line from the 
> template: http://pastebin.com/eDMQkY3H
>
> If anybody could help me with this, or tell me what I'm doing wrong, I'd 
> greatly appreciate it.
>

-- 
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/8fe9dc5a-39fb-44fe-b0a4-16bcb6709cdd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to