I try to understand what the following codeblock does inside an Ansible-Playbook
environment: '{{ inventory__environment | d({})
| combine(inventory__group_environment | d({}))
| combine(inventory__host_environment | d({})) }}'
From my understanding the environment:
Keyword sets environment variables on the target host.
The double-moustaches {{ xxx }}
mark a jinja2 expression - Correct me if Im wrong. So there happens some kind of evaluation of what is inside those brackets.
An Expression of the following format {{ x | y }}
is called a 'filter' in Ansible. It works like a pipe in Bash.
So what does this special function called d()
do?
A:
d()
is shortcut fordefault()
. For example the tasks belowwhere
dict1
,dict2
, anddict3
are not defined giveThe fiter
combine
combines the dictionaries. Let's test it. For examplegive