# How to undefine a variable?

**URL:** <https://forum.ansible.com/t/how-to-undefine-a-variable/20323>\
**Category:** Ansible Project\
**Created:** [January 22, 2016, 9:02pm UTC](https://forum.ansible.com/t/how-to-undefine-a-variable/20323 "2016-01-22T21:02:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Weiwen\_Chen](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Weiwen\_Chen](https://forum.ansible.com/u/Weiwen_Chen)\
**Post date:** [January 22, 2016, 9:02pm UTC](https://forum.ansible.com/t/how-to-undefine-a-variable/20323/1 "2016-01-22T21:02:25Z")

</div>

Help pls. I like to undefine a variable in a task.

---

<div class="post-metadata">

**Author:** ![Ankit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Ankit\_Kulkarni](https://forum.ansible.com/u/Ankit_Kulkarni)\
**Post date:** [January 23, 2016, 5:30am UTC](https://forum.ansible.com/t/how-to-undefine-a-variable/20323/2 "2016-01-23T05:30:05Z")

</div>

Setting the variable value to None could be one of the ways. You can try registering a variable value to ‘None’ while running the task .

- name: Register the value of FOO  
shell: echo VALUE  
register: FOO

- name: Set the FOO variable value from stdout  
set\_fact:  
FOO: “{{FOO.stdout}}”

Now when you access the variable FOO you will get the value None .

---

<div class="post-metadata">

**Author:** ![Weiwen\_Chen](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Weiwen\_Chen](https://forum.ansible.com/u/Weiwen_Chen)\
**Post date:** [January 24, 2016, 4:57pm UTC](https://forum.ansible.com/t/how-to-undefine-a-variable/20323/3 "2016-01-24T16:57:28Z")

</div>

Thanks for the hint. Unfortunately the variable is defined by CLI with extra\_vars option and set\_fact is not effective to it. I think the real solution is to have set\_global module, but not existing yet.
