Files
nfc_glpi/tasks/api/search/groups_id.yaml

55 lines
1.3 KiB
YAML

---
- name: Fetch users_id
ansible.builtin.uri:
url: "{{ http_protocol | default('https') | string }}://{{ glpi.host }}/apirest.php/Group?searchText[name]={{ item.groups_id | urlencode }}"
method: "GET"
return_content: true
body: ''
status_code: [200, 201]
headers:
App-Token: "{{ glpi.app_token }}"
Session-Token: "{{ glpi.session.valid_id }}"
body_format: json
validate_certs: "{{ glpi.validate_certs | default(true) | bool }}"
register: glpi_search
no_log: true
- name: Iterate over results for ID search
ansible.builtin.shell:
cmd: |
cat <<EOF
{
{%- for json in glpi_search.json -%}
{%- if json.name | string == item.groups_id | string -%}
"groups_id": {{ json.id | int }}
{%- endif -%}
{%- endfor -%}
}
EOF
args:
executable: bash
register: itarate_id
changed_when: false
no_log: true
when: >
glpi_search.json | length | int > 0
- name: Set groups_id
ansible.builtin.set_fact:
new_data: "{{ itarate_id.stdout | from_yaml }}"
when: itarate_id.stdout | default({}) | length | int > 0
- name: Append groups (have item_body)
ansible.builtin.set_fact:
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
glpi_search: {}
itarate_id: {}
new_data: {}
no_log: true