How to undefine a variable?

40 views
Skip to first unread message

Weiwen Chen

unread,
Jan 22, 2016, 9:23:06 PM1/22/16
to Ansible Project
In the task I want undefine a variable. Is that possible?

Weiwen Chen

unread,
Jan 22, 2016, 9:23:07 PM1/22/16
to Ansible Project
Help pls. I like to undefine a variable in a task.

Ankit Kulkarni

unread,
Jan 23, 2016, 12:30:06 AM1/23/16
to Ansible Project


On Saturday, January 23, 2016 at 7:53:07 AM UTC+5:30, Weiwen Chen wrote:
Help pls. I like to undefine a variable in a task.

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 . 
   

Weiwen Chen

unread,
Jan 24, 2016, 11:57:28 AM1/24/16
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages