Is there a function to update values in a json in Ansible?
Your code currently modifies the parent-dictionary, but you want to modify the the dictionary in "test2"
. To do that, you need to do this:
- name: update object set_fact: new_var: "{{ imported_var['test2'] | default({}) | combine({'test3': 'good'}) }}" - debug: var: new_var
If you are interested in the whole imported dictionary, you can do it like this:
- name: update object set_fact: new_var: "{{ imported_var | default({}) | combine({'test2': {'test3': 'good'}}, recursive=true) }}" - debug: var: new_var