# unregister a variable ?

**URL:** <https://forum.ansible.com/t/unregister-a-variable/16556>\
**Category:** Ansible Project\
**Created:** [October 20, 2014, 12:05pm UTC](https://forum.ansible.com/t/unregister-a-variable/16556 "2014-10-20T12:05:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torsten\_Reinhard](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Torsten\_Reinhard](https://forum.ansible.com/u/Torsten_Reinhard)\
**Post date:** [October 20, 2014, 12:05pm UTC](https://forum.ansible.com/t/unregister-a-variable/16556/1 "2014-10-20T12:05:39Z")

</div>

Hi all,

is it possible to “clear” or “unregister” a variable ?

I have this situation:

deploy.yml

- include “deploy-apache.yml”
- include “deploy-tomcat.yml”

deploy-apache and deploy-tomcat both have a dependency to a “deliver-artifact” role, and both run on the same server(s).  
The {{installdir}} is either opt/web/install/apache or /opt/web/install/tomcat (read from included \*.yml files)

The following task is implemented in this “shared” “deliver-artifact” role:

…

# for each run, backup the old installdir and install into an empty directory

- name: stat installdir  
stat: path={{installdir}}  
register: installdir\_stat

- name: get the current time for a timestamp  
command: date +%Y%m%d-%H%M%S  
register: time

- name: backup installdir  
command: mv {{installdir}} {{installdir}}\_{{time.stdout}}  
when: installdir\_stat.stat.exists  
…

It seems that the “installdir\_stat.stat.exists” is true from the “deploy-apache.yml” run - where {{installdir}} was /opt/web/install/apache

For “deploy-tomcat.yml” run the task now tries to mv a directory that doesnt exists - but the variable installdir\_stat.stat.exists is true !

=\> Can I clear the register ? Or what´s the solution here?

Thanx, Torsten

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 20, 2014, 6:24pm UTC](https://forum.ansible.com/t/unregister-a-variable/16556/2 "2014-10-20T18:24:35Z")

</div>

Hi Torsten,

Since there is no `when` conditional on the stat task, it should be re-run and overwrite the registered variable, so I’m a bit unclear why this would be showing the behavior you’re seeing. Is this the complete list of tasks, and/or there any other tasks that also use that registered variable name?

---

<div class="post-metadata">

**Author:** ![Torsten\_Reinhard](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Torsten\_Reinhard](https://forum.ansible.com/u/Torsten_Reinhard)\
**Post date:** [October 21, 2014, 4:07pm UTC](https://forum.ansible.com/t/unregister-a-variable/16556/3 "2014-10-21T16:07:29Z")

</div>

No there are no other modules using that variable. But The question still is: Can i clear The variable somehow?

For now i removed The stat task and when condition -and added a simple Shell if statement instead to the mv operation.

Torsten

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 21, 2014, 5:54pm UTC](https://forum.ansible.com/t/unregister-a-variable/16556/4 "2014-10-21T17:54:09Z")

</div>

Yes, you should be able to use set\_fact to initialize it to some other value and test that in your when: statement.
