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 ?