setting 'always_run' from a var

9 views
Skip to first unread message

Mike Biancaniello

unread,
Mar 2, 2016, 6:57:51 PM3/2/16
to Ansible Project
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  



Reply all
Reply to author
Forward
0 new messages