HeroFromEarth HeroFromEarth - 28 days ago 6
YAML Question

How to add dict entry after assigning variable in yaml?

I want to create a dict myVar2 that contains myVar1 and additional entry, something like this:

myVar1:
entry1: "text1"
entry2: "text2"
myVar2: "{{ myVar1 }}"
additional: "entry"


and when I try to launch ansible with this vars file then I get an error:

ERROR! Syntax Error while loading YAML.


How can I solve it?

Answer Source

Use combine filter:

myVar1:
  entry1: "text1"
  entry2: "text2"
myVarTmp:
  additional: "entry"
myVar2: "{{ myVar1 | combine(myVarTmp) }}"