Hi,

I am using a variables file for assigning values to the variables which i 
would then be using in my playbooks. Sometimes the values to these 
variables are further variables whose values are resolved at runtime, and 
sometimes they have default values as well.

vars.yaml

---

varA:"A"

VarB: 200

varC: "{{ dynamicVar | default("default_value") }}"

varDictA: "{{ Dynamic_Var.child | default("Child_value") }}"


I am using Ansible 2.3 and loading this vars file at the playbook level

---
- name: My playbook

  hosts: host1
  vars_files:
    - vars.yaml

  tasks:
    
    - debug: var=varDictA


Now the problem is that the playbook doesn't work if the dictionary var "
*Dynamic_Var*" is not defined. I do understand that i will be referencing a 
null in case it is not defined, but in my case i need it to be in a way 
that either i use a var inside dictionary or its default value, thus have 
to use it directly. In the var file, i do not even have options to use 
conditionals.

What is the best way to use a dictionary member directly or the default 
value when the whole dictionary is undefined ?

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1614572a-d515-44bd-8ccd-2ea7cb35eb5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to