Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created October 29, 2015 17:03
Show Gist options
  • Save hughsaunders/93a067fab8ffc8dda49e to your computer and use it in GitHub Desktop.
Save hughsaunders/93a067fab8ffc8dda49e to your computer and use it in GitHub Desktop.
---
- hosts: all
gather_facts: False
tasks:
- shell: date
when: false
register: rvar
- debug:
msg: "Can I use an undefined var in a conditional?"
when: rvar.rc==0
- debug:
msg: "Return code: {{rvar.rc}}"
PLAY [all] ********************************************************************
TASK: [shell date] ************************************************************
skipping: [localhost]
TASK: [debug ] ****************************************************************
ok: [localhost] => {
"msg": "Can I use an undefined var in a conditional?"
}
TASK: [debug ] ****************************************************************
fatal: [localhost] => One or more undefined variables: 'dict object' has no attribute 'rc'
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/hugh/test.retry
localhost : ok=1 changed=0 unreachable=1 failed=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment