refactor(api_config): iterate over results
changed to iterate over results as the api search is not exact, it's contains. now workflow iterates over results and on name match, exact; Adds the item id. !1
This commit is contained in:
@ -15,17 +15,39 @@
|
||||
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.entities_id | string -%}
|
||||
"entities_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 entities_id
|
||||
ansible.builtin.set_fact:
|
||||
new_data:
|
||||
entities_id: "{{ glpi_search.json[0].id | int }}"
|
||||
when: glpi_search.json | length | int == 1
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
when: itarate_id.stdout | default({}) | length | int > 0
|
||||
|
||||
|
||||
- name: Append entities_id
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data) }}"
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
@ -15,18 +15,39 @@
|
||||
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:
|
||||
groups_id: "{{ glpi_search.json[0].id | int }}"
|
||||
when: glpi_search.json | length | int == 1
|
||||
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) }}"
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
||||
|
@ -112,14 +112,10 @@
|
||||
when: itarate_id.stdout is defined
|
||||
|
||||
|
||||
- name: Append id
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data) }}"
|
||||
no_log: true
|
||||
when: new_data | default({}) | length | int > 0
|
||||
|
||||
- name: Item_id fact Cleanup
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
|
@ -15,17 +15,39 @@
|
||||
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.itilcategories_id | string -%}
|
||||
"itilcategories_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 itilcategories_id
|
||||
ansible.builtin.set_fact:
|
||||
new_data:
|
||||
itilcategories_id: "{{ glpi_search.json[0].id | int }}"
|
||||
when: glpi_search.json | length | int == 1
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
when: itarate_id.stdout | default({}) | length | int > 0
|
||||
|
||||
|
||||
- name: Append itilcategories_id
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data) }}"
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: item.itilcategories_id is defined
|
||||
|
@ -14,18 +14,39 @@
|
||||
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.tickettemplates_id | string -%}
|
||||
"tickettemplates_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 tickettemplates_id
|
||||
ansible.builtin.set_fact:
|
||||
new_data:
|
||||
tickettemplates_id: "{{ glpi_search.json[0].id | int }}"
|
||||
when: glpi_search.json | length | int == 1
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
when: itarate_id.stdout | default({}) | length | int > 0
|
||||
|
||||
|
||||
- name: Append tickettemplates_id
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data) }}"
|
||||
new_data: {}
|
||||
tickettemplates_id: "{{ glpi_search.json[0].id | int }}"
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
@ -15,17 +15,39 @@
|
||||
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.tickettemplates_id_demand | string -%}
|
||||
"tickettemplates_id_demand": {{ 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 tickettemplates_id_demand
|
||||
ansible.builtin.set_fact:
|
||||
new_data:
|
||||
tickettemplates_id_demand: "{{ glpi_search.json[0].id | int }}"
|
||||
when: glpi_search.json | length | int == 1
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
when: itarate_id.stdout | default({}) | length | int > 0
|
||||
|
||||
|
||||
- name: Append tickettemplates_id_demand
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data) }}"
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
@ -16,17 +16,39 @@
|
||||
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.users_id | string -%}
|
||||
"users_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 users_id
|
||||
ansible.builtin.set_fact:
|
||||
new_data:
|
||||
users_id: "{{ glpi_search.json[0].id | int }}"
|
||||
when: glpi_search.json | length | int == 1
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
when: itarate_id.stdout | default({}) | length | int > 0
|
||||
|
||||
|
||||
- name: Append users_id (have item_body)
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data) }}"
|
||||
item_body: "{{ item_body | ansible.builtin.combine(new_data | default({})) }}"
|
||||
glpi_search: {}
|
||||
itarate_id: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
Reference in New Issue
Block a user