Ansible set_fact sets fact even when another fact is undefined?

0down votefavorite

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

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:

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

`facts_help.yml
---
- debug:
    var: fake_fact
- debug:
    var: new_fact

- set_fact:
    new_fact: fake_fact
    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.

Thanks for the update and clarification on this !!!