I have a task that I would like to conditionally run even in check_mode 
(actually I want to set it for an entire role, but I'm seeing the same 
behavior in regular tasks).


The idea is that this would NOT run the task:
ansible-playbook always_run.yml --check

And then to actually execute the task in check_mode:

ansible-playbook always_run.yml -e '{"runit":true}' --check


But that's not the behavior I'm seeing. The problem is that alwasy_run 
always evaluates to 'true'.

Playbook (I've tried a few different variations. The only one that properly 
evaluates always_run is always_run: false):

---
- name: Do cool stuff
  hosts: localhost
  connection: local
  gather_facts: no

  vars:
    runit: false

  tasks:
  - name: show runit
    debug: var=runit
  - name: show stuff
    command: whoami
    always_run: "runit == true"
    #always_run: "{{runit|default(false)}}"
    #always_run: "{{runit}}"
    #always_run: runit
    #always_run: false
    register: me
  - name: show me
    debug: var=me.stdout_lines



Actual Results:

mikeb@mikeb-laptop:~/ansible-test$ ansible-playbook always_run.yml --check

PLAY [Do cool stuff] 
***********************************************************

TASK [show runit] 
**************************************************************
ok: [localhost] => {
    "runit": false
}

TASK [show stuff] 
**************************************************************
changed: [localhost]

TASK [show me] 
*****************************************************************
ok: [localhost] => {
    "me.stdout_lines": [
        "mikeb"
    ]
}

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

   
Expected Results:

mikeb@mikeb-laptop:~/ansible-test$ ansible-playbook always_run.yml --check

PLAY [Do cool stuff] 
***********************************************************

TASK [coolrole : show stuff from role] 
*****************************************
changed: [localhost]

TASK [show runit] 
**************************************************************
ok: [localhost] => {
    "runit": false
}

TASK [show stuff] 
**************************************************************
skipping: [localhost]

TASK [show me] 
*****************************************************************
ok: [localhost] => {
    "me.stdout_lines": "VARIABLE IS NOT DEFINED!"
}

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



-- 
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/08a9df18-1be7-4596-ba35-ecce6c8d67bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to