In a playbook, a Variable gets registered even if "when" clause is 
false...Is this a bug?

Consider this playbook

---
- name: When test
  gather_facts: false
  hosts: all
  vars:
    now: true
  tasks:
    - name: Get hostname
      shell: hostname
      register: output
      when: now == true


    - name: Get user
      shell: whoami
      register: output
      when: now != true

    - debug:
        var: output


What should be the output?
Logically, I believe it should be the result of the first play:


PLAY [When test] 
****************************************************************************

TASK [Get hostname] 
*************************************************************************
changed: [localhost]

TASK [debug] 
********************************************************************************
ok: [localhost] => {
    "changed": false,
    "output": {
        "changed": true,
        "cmd": "hostname",
        "delta": "0:00:00.003747",
        "end": "2018-03-26 16:55:48.727647",
        "rc": 0,
        "start": "2018-03-26 16:55:48.723900",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "server01",
        "stdout_lines": [
            "server01"
        ]
    }
}

PLAY RECAP 
************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0



What I actually get is:

PLAY [When test] 
*******************************************************************************

TASK [Get hostname] 
****************************************************************************
changed: [localhost]

TASK [Get user] 
********************************************************************************
skipping: [localhost]

TASK [debug] 
***********************************************************************************
ok: [localhost] => {
    "changed": false,
    "output": {
        "changed": false,
        "skip_reason": "Conditional result was False",
        "skipped": true
    }
}

PLAY RECAP 
***************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0


Or am I misunderstanding something?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/139ab0b4-8371-403d-9ebb-5ee119c8ebdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to