I had search in a few forums including this one, but none of them seems to be able to provide the solution for me. In the playbook, I am doing a call via uri
module that registers a variable: result
.
result.json
looks like this
{
"global_api_concurrency_limit": 199,
"client_api_rate_limit": 100,
"client_api_concurrency_limit": 40,
"connection_timeout": 30,
"redirect_host": "",
"protocol_versions": [
{"enabled": true, "name": "TLSv1.1"},
{"enabled": true, "name": "TLSv1.2"}
]
}
I checked via result.json | type_debug
and says its a dictionary.
I want to update property to "enabled": false
where "name": "TLSv1.1"
.
Noting that false
is not quoted in the JSON. So my idea is to either create a new dict or update the same dict. But I am stuck how I can update only that value.
I attempted the below tasks, but it obviously didn't work.
- name: Call NSXT
vars:
api: "/api/v1/cluster/api-service"
ansible.builtin.uri:
url: "https://server01{{ api }}"
user: user1
password: pwd1
method: GET
force_basic_auth: true
validate_certs: false
headers:
Content-Type: application/json
register: result
- set_fact:
newdic: "{{ (newdic | d([])) | combine(new_item, recursive=True) }}"
with_dict: "{{ result.json }}"
vars:
new_item: {'enabled': false}
when: item.protocol_versions.name == 'TLSv1.1'
Any advise how to improve this? (Note: I don't want to install jmespath
for JSON queries, because of company restrictions)
I couldn't figure out how I can only update one value with that nested dictionary?