How about moving the common authentication values into their own key in the dictionary
- name: Test variable composition
hosts: localhost
gather_facts: false
vars:
common:
var1: var1
shell: "{{ lookup('env', 'SHELL') }}"
test1:
a: 1
b: 2
common: "{{ common }}"
test2:
a: 3
b: 4
common: "{{ common }}"
tasks:
- debug: var=common
- debug: var=test1
- debug: var=test2
Output(ansible)[ec2-user@ip-10-0-0-226 playbooks]$ ansible-playbook -i launched test_output.yml
PLAY [Test variable composition] **********************************************
TASK: [debug var=common] ******************************************************
ok: [localhost] => {
"common": {
"shell": "/bin/bash",
"var1": "var1"
}
}
TASK: [debug var=test1] *******************************************************
ok: [localhost] => {
"test1": {
"a": 1,
"b": 2,
"common": {
"shell": "/bin/bash",
"var1": "var1"
}
}
}
TASK: [debug var=test2] *******************************************************
ok: [localhost] => {
"test2": {
"a": 3,
"b": 4,
"common": {
"shell": "/bin/bash",
"var1": "var1"
}
}
}
PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
Thanks!
Michael