I am new to ansible , i have below response which is coming from rest uri
[{??
"id": 1,
"clientId": "client1",
"name": "client first"
},
{
"id": 2,
"clientId": "client2",
"name": "client first"
},
{
{
"id": 3,
"clientId": "client3",
"name": "client three"
}
}
]
I want to loop over the above json response and wants exclude some of the client Id like "clientId": "client1"
then add those clientIds like client2, client3 in list client_id_to_be_create
Below is my code snippet
- name: initialize container variables
set_fact:
client_to_be_excluded: [client1]
client_id_to_be_create: [] // only append those client in this list
- name: Create new client mapper for all clients
block:
- name: get clients
local_action:
module: uri
url: "{{ host_url }}/clients"
method: GET
headers: "{{ host_headers }}"
status_code: 200
validate_certs: "{{ validate_certs }}"
register: get_clients
- name: "Find clients"
loop: "{{ get_clients.json }}"
when: not get_clients.clientId in client_to_be_excluded"
loop_control:
label: "{{ get_clients.clientId }}"
question from:
https://stackoverflow.com/questions/65840953/ansible-for-loop-json-witj-filter-of-some-records 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…