# Reset vars between plays on same host

**URL:** <https://forum.ansible.com/t/reset-vars-between-plays-on-same-host/18760>\
**Category:** Ansible Project\
**Created:** [July 14, 2015, 8:23pm UTC](https://forum.ansible.com/t/reset-vars-between-plays-on-same-host/18760 "2015-07-14T20:23:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Tkach](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@Nick\_Tkach](https://forum.ansible.com/u/Nick_Tkach)\
**Post date:** [July 14, 2015, 8:23pm UTC](https://forum.ansible.com/t/reset-vars-between-plays-on-same-host/18760/1 "2015-07-14T20:23:41Z")

</div>

Is there a way to somehow “reset” variables in-between plays? What I’m trying to do is make a playbook that creates my standard tomcat instance layout.

So given the setup below, as I understand it you’d have “app” files group\_vars where you could set whatever things specific to that app instance like port. Then you’d have in the roles/tomcat-7/defaults/main.yml some default values for everything with the idea you’d set what you actually care about in the top level group\_vars/app1.yml and app2.yml such as port number for that specific app. Then you use an inventory file for a given environment (such as dev.hosts) to “hook” together a given app with a given group of host(s). Then you call ansible-playbook passing in the inventory file you care about right now (such as dev.hosts), the top level playbook (such as tomcat7servers.yml), Then Ansible would iterate through the playbook ( tomcat7servers.yml in this case), taking the group\_vars/myapp1 and run the tomcat-7 role on the myapp1 group of hosts. Then the same for myapp2.

That much seems like it works, but the problem I get is that there doesn’t seem to be a way to say ok, this time around I don’t want to do both myapp1 and myapp2. I want to limit to just myapp2. I’ve tried doing something like

ansible-playbook -i dev.hosts tomcat7servers.yml --limit=myapp2

but it picks up both. Not only that but unless I re-define values from the myapp1 “run” it keeps the values from myapp1 when it hits myapp2. This usually suggests I’m not “getting” something about how Ansible models things. What am I “missing” about this picture? I want to be able to run something like I gave above there and have a tomcat 7 on appsvr1.internal created that has totally default except for the values explicitly set in group\_vars/myapp1 and another tomcat 7 on that same box that has totally default values except for what’s explcitly set in group\_vars/myapp2.

/usr/local/apache-tomcat-7.0.51 (where this is just a totally plain tar xzf of a tarball off Apache’s site extracted as root so it’s _NOT_ writable)

Then the tomcat instances (owned by app user such as tcadm):  
/appl/app1/  
then under that  
/bin  
/conf/  
/webapps  
and so on

/appl/appt2/  
same setup as app1 here, but different ports, different instance name

So, trying to extrapolate from Ansible best practices in the documentation the local “repo” is something like this

roles/tomcat-7/defaults/main.yml (where you’d set things you don’t normally care about overriding like maxAjpThreads but you _could_ override what’s in the group\_vars top level)  
roles/tomcat-7/tasks  
roles/tomcat-7/templates  
and so on

group\_vars/ (where you’d have yml files with the values for a given app-such as myapp1.yml, myapp2.yml)  
(example myapp1.yml)

`  
ajpPort: 8109  
httpPort: 8180  
instanceName: myapp1

`  
(example myapp2.yml)

`  
ajpPort: 8209  
httpPort: 8280  
instanceName: myapp2

`

dev.hosts (which would match up group\_names (such as myapp1 and myapp2) to actual hosts in dev environment)

`  
(example dev.hosts)  
[myapp1]  
appsvr1.dev

[myapp2]  
appsvr1.dev

`

tomcat7servers.yml (“matching” groups for the inventory to actual roles)

`

- hosts: myapp1  
become\_user: tomcat  
roles:

- tomcat-7  
tasks:

- include\_vars: group\_vars/myapp1.yml

- host: myapp2  
become\_user: tomcat  
roles:

- tomcat-7  
tasks:

- include\_vars: group\_vars/myapp2.yml

`
