# Ansible set\_fact sets fact even when another fact is undefined?

**URL:** <https://forum.ansible.com/t/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined/28384>\
**Category:** Ansible Project\
**Created:** [August 21, 2018, 3:05pm UTC](https://forum.ansible.com/t/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined/28384 "2018-08-21T15:05:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ford\_FasteRR](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@Ford\_FasteRR](https://forum.ansible.com/u/Ford_FasteRR)\
**Post date:** [August 21, 2018, 3:05pm UTC](https://forum.ansible.com/t/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined/28384/1 "2018-08-21T15:05:15Z")

</div>

0down vote[favorite](https://superuser.com/questions/1345726/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined#)

I’m seeing strange behavior in ansible 2.5.5 (on centos 6.10)

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [August 21, 2018, 3:39pm UTC](https://forum.ansible.com/t/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined/28384/2 "2018-08-21T15:39:48Z")

</div>

The when clause should line up under set\_fact. When I indent it properly, that play is skipped as expected. Not sure why the wrongly indented version is not picked up as a syntax error.

Here is the playbook I ran:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 21, 2018, 3:43pm UTC](https://forum.ansible.com/t/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined/28384/3 "2018-08-21T15:43:28Z")

</div>

> I'm seeing strange behavior in ansible 2.5.5 (on centos 6.10)
> 
> `facts\_help.yml  
> ---  
> - debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;var: fake\_fact  
> - debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;var: new\_fact
> 
> - set\_fact:  
> &nbsp;&nbsp;&nbsp;&nbsp;new\_fact: fake\_fact  
> &nbsp;&nbsp;&nbsp;&nbsp;when: fake\_fact is defined

Indentation error, when: is a property for the task.  
Here you set a variable called when to the string "fake\_fact is defined"

> As you can see, fake\_fact is undefined, and debug validates that. The when:  
> clause evaluates to true, and allows new\_fact to be set (that's my  
> problem)..
> 
> Afterwards, a repeat of the debug on fake\_fact still appears undefined.
> 
> So I'm not sure if this really a feature that I don't understand, a bug, or  
> just a user error?

User error.

---

<div class="post-metadata">

**Author:** ![Ford\_FasteRR](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@Ford\_FasteRR](https://forum.ansible.com/u/Ford_FasteRR)\
**Post date:** [August 21, 2018, 4:07pm UTC](https://forum.ansible.com/t/ansible-set-fact-sets-fact-even-when-another-fact-is-undefined/28384/4 "2018-08-21T16:07:14Z")

</div>

Thanks for the update and clarification on this !!!
