@ -1,10 +1,48 @@
|
||||
---
|
||||
|
||||
- name: Show item
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ item }}"
|
||||
|
||||
- name: Create item_body
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item.body }}"
|
||||
no_log: true
|
||||
|
||||
- name: Search item_id
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/item_id.yaml
|
||||
when: >
|
||||
not item.body.id is defined
|
||||
when: not item.body.id is defined
|
||||
|
||||
|
||||
- name: Search entities_id
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/entities_id.yaml
|
||||
when: item.entities_id is defined
|
||||
|
||||
|
||||
- name: Search itilcategories_id
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/itilcategories_id.yaml
|
||||
when: item.itilcategories_id is defined
|
||||
|
||||
|
||||
- name: Search tickettemplates_id_demand
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/itickettemplates_id_demand.yaml
|
||||
when: item.tickettemplates_id_demand is defined
|
||||
|
||||
|
||||
- name: Search tickettemplates_id
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/tickettemplates_id.yaml
|
||||
when: item.tickettemplates_id is defined
|
||||
|
||||
|
||||
- name: Search users_id
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/users_id.yaml
|
||||
when: item.users_id is defined
|
||||
|
||||
|
||||
- name: Show Body
|
||||
@ -15,7 +53,7 @@
|
||||
|
||||
- name: Create Item
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}"
|
||||
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}{% if item.sub_path is defined %}/{{ item.sub_path }}{% endif %}"
|
||||
method: "POST"
|
||||
return_content: true
|
||||
body: "{\"input\": {{ item_body | from_yaml | to_json }} }"
|
||||
@ -25,12 +63,14 @@
|
||||
Session-Token: "{{ glpi.session.valid_id }}"
|
||||
body_format: json
|
||||
no_log: true
|
||||
when: not item_body.id is defined
|
||||
register: create_item
|
||||
when: >
|
||||
not item_body.id is defined
|
||||
|
||||
|
||||
- name: Update Item
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}{% if item.api_path != 'Config' %}/{{ item_body.id }}{% endif %}"
|
||||
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}{% if item.sub_path is defined %}/{{ item.sub_path }}{% else %}{% if item.api_path != 'Config' %}/{{ item_body.id | default('') }}{% endif %}{% endif %}"
|
||||
method: "PATCH"
|
||||
return_content: true
|
||||
body: "{\"input\": {{ item_body | from_yaml | to_json }} }"
|
||||
@ -40,9 +80,21 @@
|
||||
Session-Token: "{{ glpi.session.valid_id }}"
|
||||
body_format: json
|
||||
no_log: true
|
||||
register: update_item
|
||||
when: item_body.id is defined
|
||||
|
||||
|
||||
- name: Fail on no action
|
||||
ansible.builtin.fail:
|
||||
msg: No action carried out, stop.
|
||||
when: >
|
||||
update_item.skipped | default(false) | bool
|
||||
and
|
||||
create_item.skipped | default(false) | bool
|
||||
|
||||
|
||||
- name: Clear temp vars
|
||||
ansible.builtin.set_fact:
|
||||
item_body: {}
|
||||
create_item: {}
|
||||
update_item: {}
|
||||
|
@ -1,15 +1,18 @@
|
||||
---
|
||||
|
||||
- name: Create item_body
|
||||
ansible.builtin.set_fact:
|
||||
item_body: "{{ item.body }}"
|
||||
no_log: true
|
||||
- name: Ticket Template
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/ticket_template.yaml
|
||||
when: item.api_path == 'TicketTemplate'
|
||||
|
||||
|
||||
- name: Append/Create Item
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/append-create-item.yaml
|
||||
when: not item.api_path == 'Config'
|
||||
when: >
|
||||
not item.api_path == 'Config'
|
||||
and
|
||||
not item.api_path == 'TicketTemplate'
|
||||
|
||||
|
||||
- name: Config Items to skip
|
||||
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
- name: Find Item ID
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}?searchText[name]={{ item.body.name | urlencode }}"
|
||||
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}{% if item.sub_path is defined %}/{{ item.sub_path }}{% endif%}{% if search_items | length | int > 0%}?{% for search in search_items %}searchText[{{ search.name }}]={{ search.value | urlencode }}&{% endfor %}{% else%}?searchText[name]={{ item.body.name | urlencode }}{% endif %}"
|
||||
method: "GET"
|
||||
return_content: true
|
||||
body: ''
|
||||
@ -22,10 +22,102 @@
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
||||
|
||||
- name: Iterate over results for TicketTemplateMandatoryField id/TicketTemplateHiddenField
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
cat <<EOF
|
||||
{
|
||||
{%- for json in glpi_search.json -%}
|
||||
|
||||
{%- if
|
||||
json.tickettemplates_id | int == item_body.tickettemplates_id | int
|
||||
and
|
||||
json.num | int == item_body.num | int
|
||||
-%}
|
||||
"id": {{ json.id | int }}
|
||||
{%- endif -%}
|
||||
|
||||
{%- endfor -%}
|
||||
}
|
||||
EOF
|
||||
args:
|
||||
executable: bash
|
||||
register: itarate_id
|
||||
changed_when: false
|
||||
when: >
|
||||
glpi_search.json | length | int > 1
|
||||
and
|
||||
(
|
||||
'TicketTemplateMandatoryField' in item.sub_path | default('')
|
||||
or
|
||||
'TicketTemplateHiddenField' in item.sub_path | default('')
|
||||
)
|
||||
|
||||
|
||||
- name: Set iterate id
|
||||
ansible.builtin.set_fact:
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
when: itarate_id.stdout is defined
|
||||
|
||||
|
||||
- name: Iterate over results for TicketTemplatePredefinedField id
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
cat <<EOF
|
||||
{
|
||||
{%- for json in glpi_search.json -%}
|
||||
|
||||
{%- if
|
||||
json.num | int == 13
|
||||
and
|
||||
json.tickettemplates_id | int == item_body.tickettemplates_id | int
|
||||
and
|
||||
json.num | int == item_body.num | int
|
||||
and
|
||||
json.value == item_body.value
|
||||
-%}
|
||||
|
||||
"id": {{ json.id | int }}
|
||||
|
||||
|
||||
{%- elif
|
||||
json.num | int != 13
|
||||
and
|
||||
json.tickettemplates_id | int == item_body.tickettemplates_id | int
|
||||
and
|
||||
json.num | int == item_body.num | int
|
||||
-%}
|
||||
"id": {{ json.id | int }}
|
||||
|
||||
{%- endif -%}
|
||||
|
||||
{%- endfor -%}
|
||||
}
|
||||
EOF
|
||||
args:
|
||||
executable: bash
|
||||
register: itarate_id
|
||||
changed_when: false
|
||||
when: >
|
||||
glpi_search.json | length | int > 1
|
||||
and
|
||||
'TicketTemplatePredefinedField' in item.sub_path | default('')
|
||||
|
||||
|
||||
- name: Set iterate id
|
||||
ansible.builtin.set_fact:
|
||||
new_data: "{{ itarate_id.stdout | from_yaml }}"
|
||||
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:
|
||||
glpi_search: {}
|
||||
new_data: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
||||
|
31
tasks/api/search/tickettemplates_id.yaml
Normal file
31
tasks/api/search/tickettemplates_id.yaml
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
- name: Fetch tickettemplates_id
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ glpi.host }}/apirest.php/TicketTemplate?searchText[name]={{ item.tickettemplates_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
|
||||
register: glpi_search
|
||||
no_log: true
|
||||
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
- 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 }}"
|
||||
glpi_search: {}
|
||||
no_log: true
|
||||
when: glpi_search.json | length | int == 1
|
103
tasks/api/ticket_template.yaml
Normal file
103
tasks/api/ticket_template.yaml
Normal file
@ -0,0 +1,103 @@
|
||||
---
|
||||
|
||||
- name: Template item
|
||||
ansible.builtin.set_fact:
|
||||
template_item: "{{ item }}"
|
||||
|
||||
|
||||
- name: Append/Create TicketTemplate
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/append-create-item.yaml
|
||||
when: item.api_path == 'TicketTemplate'
|
||||
vars:
|
||||
item:
|
||||
api_path: TicketTemplate
|
||||
entities_id: "{{ template_item.entities_id }}"
|
||||
body: "{{ template_item.body }}"
|
||||
|
||||
|
||||
- name: Search tickettemplates_id
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/search/tickettemplates_id.yaml
|
||||
vars:
|
||||
item:
|
||||
tickettemplates_id: "{{ template_item.body.name }}"
|
||||
|
||||
|
||||
- name: Append/Create Ticket Template Mandatory Fields
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/append-create-item.yaml
|
||||
when: >
|
||||
template_item._TicketTemplateMandatoryField is defined
|
||||
and
|
||||
template_item._TicketTemplateMandatoryField | length | int > 0
|
||||
loop: "{{ template_item._TicketTemplateMandatoryField }}"
|
||||
loop_control:
|
||||
loop_var: sub_item
|
||||
vars:
|
||||
search_items:
|
||||
- name: tickettemplates_id
|
||||
value: "{{ tickettemplates_id }}"
|
||||
- name: num
|
||||
value: "{{ sub_item.num }}"
|
||||
item:
|
||||
api_path: TicketTemplate
|
||||
sub_path: "{{ tickettemplates_id }}/TicketTemplateMandatoryField"
|
||||
body:
|
||||
num: "{{ sub_item.num }}"
|
||||
tickettemplates_id: "{{ tickettemplates_id | int }}"
|
||||
|
||||
|
||||
- name: Append/Create Ticket Template Predefined Fields
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/append-create-item.yaml
|
||||
when: >
|
||||
template_item._TicketTemplatePredefinedField is defined
|
||||
and
|
||||
template_item._TicketTemplatePredefinedField | length | int > 0
|
||||
loop: "{{ template_item._TicketTemplatePredefinedField }}"
|
||||
loop_control:
|
||||
loop_var: sub_item
|
||||
vars:
|
||||
search_items:
|
||||
- name: tickettemplates_id
|
||||
value: "{{ tickettemplates_id }}"
|
||||
- name: num
|
||||
value: "{{ sub_item.num }}"
|
||||
item:
|
||||
api_path: TicketTemplate
|
||||
sub_path: "{{ tickettemplates_id }}/TicketTemplatePredefinedField"
|
||||
body:
|
||||
num: "{{ sub_item.num | int }}"
|
||||
tickettemplates_id: "{{ tickettemplates_id | int }}"
|
||||
value: "{{ sub_item.value | string }}"
|
||||
|
||||
|
||||
- name: Append/Create Ticket Template Hidden Fields
|
||||
ansible.builtin.include_tasks:
|
||||
file: api/append-create-item.yaml
|
||||
when: >
|
||||
template_item._TicketTemplateHiddenField is defined
|
||||
and
|
||||
template_item._TicketTemplateHiddenField | length | int > 0
|
||||
loop: "{{ template_item._TicketTemplateHiddenField }}"
|
||||
loop_control:
|
||||
loop_var: sub_item
|
||||
vars:
|
||||
search_items:
|
||||
- name: tickettemplates_id
|
||||
value: "{{ tickettemplates_id }}"
|
||||
- name: num
|
||||
value: "{{ sub_item.num }}"
|
||||
item:
|
||||
api_path: TicketTemplate
|
||||
sub_path: "{{ tickettemplates_id }}/TicketTemplateHiddenField"
|
||||
body:
|
||||
num: "{{ sub_item.num | int }}"
|
||||
tickettemplates_id: "{{ tickettemplates_id | int }}"
|
||||
|
||||
|
||||
- name: Clear temp vars
|
||||
ansible.builtin.set_fact:
|
||||
template_item: {}
|
||||
no_log: true
|
Reference in New Issue
Block a user