Assigning one variable to another

Hi,

I want to ask what is the correct syntax for assigning one variable to another? I wish to do this in roles/for/vars/main.yml.

It should be something like:

ip_address: {{ static_ip_address }}

but I think I’ve read somewhere that yml requires quotes around the template:

ip_address: “{{ static_ip_address }}”

is this correct?

Thanks
James

​Yes. Without the quoting, yaml interprets this as a hash.​

Playbooks must be valid YAML, so, quotes are needed since you cannot start a YAML string with a curly brace ‘{’ character, because that character is used to define YAML dictionaries. If you were to use the var in the middle of a string though you would not need to use quotes. For example, the following syntax is correct: welcome_message: Hello {{ name }}

Another use-case.
Say I have two of variables:

newrelic``_license_key``: null
newrelic_environment: null
newrelic: no

And if I need to test if there is need to install newrelic on a server I need to write this:

when: newrelic and newrelic_license_key is not none and newrelic_environment is not none

I would prefer to do this:

newrelic``_license_key``: null
```newrelic_environment: null newrelic: no use_newrelic: {{ ``newrelic and newrelic_license_key is not none and newrelic_environment is not none }}`

And then use use_newrelic in all conditional statements.

There is a workaround for this: wrap use_newrelic value to quotes and then check it in that way: use_newrelic == "True"