On 14.02.2018 13:01, jn.be...@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

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5acdfc44083f9d3d48a4f3c237166e69%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to