Hi Kai

You used the variable in a playbook, maybe that works. But I want to make 
sure that the role is not being executed when someone forgets to set the 
So the trick here is: "{{ APPLICATIONNAME }}" is not set.
Normaly this is a variable in vars/app1.yml
Here is the full code:

#normally this var is set, but we want to provoke an error

 - name: play1
   hosts: app1
   - "vars/app1.yml"

  - include_role:
      name: role1
      applicationname: "{{ APPLICATIONNAME }}"
      description: "{{ DESCRIPTION }}"

 - applicationname

applicationname: ""
description: ""

- debug:
    var: vars

- debug:
    var: applicationname

- 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 }}" 


TASK [role1 : debug] ***********************************************
ok: [server1] => {
    "vars": {

        "applicationname": "{{ APPLICATIONNAME }}"

TASK [role1 : debug] 
ok: [SERVER1] => {
    "applicationname": "VARIABLE IS NOT DEFINED!"

TASK [role1 : check required vars when applicationname is not defined] 
skipping: [server1] => (item=applicationname)  => {"changed": false, 
"item": "applicationname", "skip_reason": "Conditional result was False"}

Or is my approach completely wrong?

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 
For more options, visit https://groups.google.com/d/optout.

Reply via email to