exit if shell variable is not set

7 views
Skip to first unread message

brentgc...@gmail.com

unread,
Aug 21, 2015, 9:13:18 AM8/21/15
to Ansible Project
Good day Guys

Is there a way I can ansible to exit and print a custom error message if a bash / shell variable is not set.

If anyone can assist, it would be appreciated.

Thanks
Brent

Brian Coca

unread,
Aug 21, 2015, 10:00:41 AM8/21/15
to Ansible Project
- hosts: localhost
gather_facts: false
tasks:
- fail: msg="lola is not set"
when: lookup('env', 'lola') == ''

This fails the play
#>ansible-playbook play.yml

PLAY ***************************************************************************

TASK [fail msg=lola is not set] ************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true,
"msg": "lola is not set"}

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



And this continues play
#>lola=is ansible-playbook play.yml

PLAY ***************************************************************************

TASK [fail msg=lola is not set] ************************************************
skipping: [localhost]

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


note that the fail is 'per host'
--
Brian Coca
Reply all
Reply to author
Forward
0 new messages