On 14.02.2018 13:01,
jn.b...@gmail.com wrote:
> I was too fast with my answer.
>
> /roles/defaults/main.yml
> ---
> applicationname: ""
> description: ""
>
> required_vars:
> - applicationname
>
<snip />
> But this doesn't work:
> - name: check required vars undefined
> fail: msg="Variable '{{ item }}' is null"
> when: vars[item] is not defined
> with_items: "{{ required_vars }}"
It does, when I do a test
---
- hosts: localhost
gather_facts: false
vars:
required_vars:
- applicationname
tasks:
- name: check required vars when applicationname is not defined
debug: msg="Variable '{{ item }}' is not defined"
when: vars[item] is not defined
with_items: "{{ required_vars }}"
- set_fact:
applicationname: ''
- name: check required vars when applicationname is defined
debug: msg="Variable '{{ item }}' is not defined"
when: vars[item] is not defined
with_items: "{{ required_vars }}"
The output
TASK [check required vars when applicationname is not defined]
************************
ok: [localhost] => (item=applicationname) => {
"item": "applicationname"
}
MSG:
Variable 'applicationname' is not defined
TASK [set_fact]
***********************************************************************
ok: [localhost]
TASK [check required vars when applicationname is defined]
****************************
skipping: [localhost] => (item=applicationname)
> TASK [role1 : check required undefined]
> **********************************************
> skipping: [server1] => (item=applicationname) => {"changed": false,
> "item": "applicationname", "skip_reason": "Conditional result was
> False"}
>
>
>
> I think
> vars[item] is not defined
> does not work because the variable "applicationname" in fact does have
> a
> value: "{{ APPLICATIONNAME }}"
I don't understand where "{{ APPLICATIONNAME }}" comes from, you have
nothing like that in you code.
--
Kai Stian Olstad