Variabla variable name, or dynamic variables...

Hi,

I’m trying to accomplish something like this.

I have a variable defined with register. Let’s call it just json output. That’s a json output from an API. Content look like:

{
“my.server”: {
“not_after”: “2019-11-27T21:36:56UTC”,
“not_before”: “2014-11-27T21:36:56UTC”,
“serial”: 1
},
[… and many more …]

}

To get the information, I have a variable named vm_name (defined in vars: ) which has “my.server” as content

I want to run through my json stream, and find the above entry. Tried to do something like:

debug:
msg=“{{ output[‘{{ vm_name }}’] }}”

which , obviously, does not work.

How can I do to actually expand {{ output[‘{{ vm_name }}’] }} to actually perform: {{output[‘my.server’]}}

Thanks!

Christian

“{{ output[vm_name] }}”

You can think of {{ }} as a code block, so anything inside of that should be referenced as bare variables.

Oh! Great!

Thank you for that. That’ll help to understand a lot of things, then! :slight_smile: