diff --git a/tasks/api/search/users_id.yaml b/tasks/api/search/users_id.yaml new file mode 100644 index 0000000..07e1afb --- /dev/null +++ b/tasks/api/search/users_id.yaml @@ -0,0 +1,32 @@ +--- + +- name: Fetch users_id + ansible.builtin.uri: + url: "http://{{ glpi.host }}/apirest.php/User?searchText[name]={{ item.users_id | urlencode }}" + method: "GET" + return_content: true + body: '' + # status_code: "{{ item.status_code | from_yaml | list }}" + status_code: [200, 201] + headers: + App-Token: "{{ glpi.app_token }}" + Session-Token: "{{ glpi.session.valid_id }}" + body_format: json + register: glpi_search + no_log: true + + +- name: Set users_id + ansible.builtin.set_fact: + new_data: + users_id: "{{ glpi_search.json[0].id | int }}" + when: glpi_search.json | length | int == 1 + + +- name: Append users_id (have item_body) + ansible.builtin.set_fact: + item_body: "{{ item_body | ansible.builtin.combine(new_data) }}" + glpi_search: {} + new_data: {} + no_log: true + when: glpi_search.json | length | int == 1