I am trying to make sense of a variable reference I found in an incomplete Ansible role. The role references a value using
dest: “{{params['box'].t1}}”
In a separate yaml file I have
box:
t1: "Albany"
t2: "Albuquerque"
params isn't defined, so obviously this isn't going to work, but I can't figure out the correct way to define it. Can someone tell me where (or how) params must be defined for this variable reference to work in Ansible?
Related questions. Does the use of square brackets in dest: “{{params['box'].t1}}”
indicate that it is a dictionary? If yes, could I also write this as dest: “{{params['box']['t1']}”
or dest: “{{params.box.t1}”
?
params['box'].t1
refers toAlbany
in:It is the same as
params.box.t1
andparams['box']['t1']
.Brackets refer to a key name, so they imply it is a dictionary.
You typically use square bracket-notation when you want to refer to a key via a variable:
Then
params[wanted_key].t1
refers toAlbany
.In your example the value inside square brackets is a string (quoted), so all above examples are equivalent.