I have a json object in an Ansible variable (my_var
), which contains values similar to the following:
{
"Enabled": "true"
"SomeOtherVariable": "value"
}
I want to modify the value of Enabled
in my_var
and have tried the following:
set_fact:
my_var.Enabled: false
and
set_fact:
my_var['Enabled']: false
Which both give errors similar to:
"The variable name 'my_var.Enabled' is not valid. Variables must start
with a letter or underscore character, and contain only letters,
numbers and underscores."
Can this be done with set_fact or is there some other way of achieving this?
Willem van Ketwich :
this was my solution - probably not the most eloquent:\n\n- set_fact:\n my_temp_enabled_var: '{ \"Enabled\": \"false\" }'\n\n- set_fact:\n my_temp_enabled_var: \"{{ my_temp_enabled_var | from_json }}\"\n\n- set_fact:\n my_var: \"{{ my_var | combine(my_temp_enabled_var) }}\"\n",
2017-01-03T02:07:43