Skip to content

Instantly share code, notes, and snippets.

@halberom
Created September 16, 2015 10:07
Show Gist options
  • Save halberom/62a3abb110f32960370c to your computer and use it in GitHub Desktop.
Save halberom/62a3abb110f32960370c to your computer and use it in GitHub Desktop.
ansible - example of asserting that vars are defined with_items
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
$ ansible-playbook --version
ansible-playbook 1.9.3
configured module search path = ~/git/ansible-modules-core:~/git/ansible-modules-extra:./library
$ ansible-playbook play.yml
ok: [localhost]
TASK: [assert ] ***************************************************************
ok: [localhost] => (item=foo)
failed: [localhost] => (item=bar) => {"assertion": "bar is defined", "evaluated_to": false, "failed": true, "item": "bar"}
failed: [localhost] => (item=abc) => {"assertion": "abc is defined", "evaluated_to": false, "failed": true, "item": "abc"}
failed: [localhost] => (item=def) => {"assertion": "def is defined", "evaluated_to": false, "failed": true, "item": "def"}
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/glynch/assert_vars_defined.retry
localhost : ok=1 changed=0 unreachable=0 failed=1
---
- hosts: localhost
vars:
foo: bar
tasks:
- assert: { that: "{{ item }} is defined" }
with_items:
- foo
- bar
- abc
- def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment