Skip to content

Commit

Permalink
Added RITM EDA return
Browse files Browse the repository at this point in the history
  • Loading branch information
adworjan committed Nov 22, 2024
1 parent 9601783 commit 5ad43a9
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .ansible-sign/sha256sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ db0cf6bab374ea48077c3898aea1602a570541a49ed82797b7459c9ce9a9824c ServiceNowCR_c
97c831eff1abac9212abac46eb8922f93ecc8a3e092e0bd8545cb183fd30bff6 ServiceNowCR_implement.yml
ad1359a3104a9025cd6a4aa589c750cb76c11470cbe3edd520689e991f0efcf1 ServiceNowCatalog.yml
c376ddf5ff1d4d02f5bf92d54a93db9ab1d5ecdcd17e7eff18c5e5bcedef6560 ServiceNowCatalogCreate.yml
b0872d90ff7a6c36d2e0602c36a8b9591d99c0c8fefa364c0e38913079dc051b ServiceNowEDARITM.yml
70072af3bc9b91fb1de27f6c16c910de46253f14e97e816bc22ab4c4f40a1f01 ServiceNow_change_request_schedule.yml
bde5f9bac8fc06d1948700fb6ed38b6e2255467918e9423cf08ffa08d3bbaad6 ServiceNow_cmdb_update.yml
206e122858f3ae645854e7624a96b16ada1936f15b623a8f34cd1deb5dfe234d ServiceNowticket.yml
Expand Down Expand Up @@ -131,6 +132,7 @@ f24230fbcf3e3e8ead1a35ca1bc06ee6279cdd60180129a1d78e90dced09ce8f roles/servicen
a464004cbb41d95d683f7a25ae37a1813d17be673a1b2a834186ac123bd961fb roles/servicenow_change_request_wait/defaults/main.yml
5c15d56df4f343e4cee23d1f94953b6ff9f524ada30033d0c488835bbdcea6eb roles/servicenow_change_request_wait/tasks/main.yml
de2faeda622d9985f01ed5df7b6af5367c9cd9549f07482331906bb9c444a022 roles/servicenow_cmdb/tasks/main.yml
ac90fc7ab64f0cec215047ccdd496186461b8db7619143fd04cd36c77afd0d95 roles/servicenow_ritm_retrieve_eda/tasks/main.yml
70c16b04f073bd76d518d043e29db8b862d2b48d72ffa3ce9d61279e370efdc4 roles/servicenow_ticket/defaults/main.yml
b8cab364bf2b85691fae7cf83f1340ae5e5b4fe0f6829068ab6955c924651412 roles/servicenow_ticket/tasks/main.yml
fe2192caf1621560b49616cf159cee58ceace50035641059bc52d5ed4b2f62f5 roles/servicenow_ticket/tasks/servicenow_close.yml
Expand Down
22 changes: 11 additions & 11 deletions .ansible-sign/sha256sum.txt.sig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-----BEGIN PGP SIGNATURE-----

iQGzBAABCAAdFiEE/bJvyFHKKJdaZDOLTiIiIXrUDNEFAmc8lpAACgkQTiIiIXrU
DNFlHAv/eLejbJh4nP8fJXY/3Je3M3w1aFt+BJ229wibPmwRm9xQXmJysX8JLD9t
LGtMOaGTWF5gpauqHimSTh5+F6zxO8PLW5qn0JszWSBhqpSpDzry0KLraYzSyHhA
3LMoHeZ5+Yt/T/Ii/TiEL1AvX5MEMCEXvLF11nwBMVxxOl/bTCv+koDmsjEUJXv7
JqcFMYvNoLJFPc+Bnhk7bjL5Dr5kXBtc4aRx37k83Q03uEa0un0mFtw1pRA76Yl3
pcLIgdYaQsJ0BeHT07/5sXfrjXIypscKQmPg3jSc1qVJ+aeVmACsXx7E+zLPRzgj
6bESBDVqyobLkaOUBq+mlYTCqJbiJbz18JezcqpeuUROcrQYgW7kXukr2XXoHXY0
pSYL/OARIwc6ZzsG8OQwZpx7H5+geGmRm2iGWY4laCnaTuEZne3gG3Ge78krVTlC
Tn529wL4Kdx8hAebV6hcJuAQwdUCz6jAqwlR2eY19tk2oQkHhKWH6S697eiG7M82
ltLVumG8
=FL1O
iQGzBAABCAAdFiEE/bJvyFHKKJdaZDOLTiIiIXrUDNEFAmdAp+4ACgkQTiIiIXrU
DNE9aQwAjTXum+scQ1eCRUIo0KZAd8XK2/3tL2fRJgqshkf0T8Nu8Gcb6V2rcpNw
9lDmTyIUyfI/S/IibjnlRsCqMRWIzzN1iqJHZjdYj8JwRJERgvYSi3A7j1/0NgpJ
VXMn2Bp7G13h/E7mhjjQCpLyEdeL4wmdZsWygkhVNQouKgUNLILJaWbtL7u+3eHh
zvuhL0hNbMmn1zw6ozT2lkmiKEtSpwl4wB/pInM0I/DLF945vAU7Em04AZqbsrpi
w+iOa/LjDYc8spV/ir11n4lP354fqlugLpPyNsQXiuw0eRcFkzuzLYDbtQBXXcXj
PJcEdud/Xz9Pb7e9F50wGQeqHy+wrDC3zC5WooB2722Z09lMpJkjW0Ho49IFdqwy
83v+feLNm33QXhz9R6+ZTsD/F0keKWq1lPHob3bXFQfxl4utVqFo1ZkWHWo+XJCF
5FZt89FPdJUb4q17hfpyulrJJyx0kHq/Klbo6Zf4EOtKbKb+ch+8xr/EJwQlDI44
X+UiqARM
=gyCW
-----END PGP SIGNATURE-----
7 changes: 7 additions & 0 deletions ServiceNowEDARITM.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Retrieve RITM from EDA Trigger
hosts: localhost
gather_facts: false

roles:
- servicenow_ritm_retrieve_eda
118 changes: 118 additions & 0 deletions roles/servicenow_ritm_retrieve_eda/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---

- name: Retrieve RITM details with retries
servicenow.itsm.api_info:
resource: sc_req_item
sysparm_query: request={{ req_sys_id }}
display_value: all
columns: [sys_id, number, description, short_description, cat_item]
register: ritms
until: ritms.record is defined and ritms.record | length > 0
retries: 3
delay: 5

- name: Set RITM details fact
ansible.builtin.set_fact:
ritm_details: "{{ ritms.record }}"
cacheable: true

- name: Retrieve variable mappings with retries
servicenow.itsm.api_info:
resource: sc_item_option_mtom
sysparm_query: request_itemIN{{ ritm_details | map(attribute='sys_id.value') | join(',') }}
columns: [sc_item_option, request_item]
register: variable_mappings
when: ritm_details | length > 0
until: variable_mappings.record is defined and variable_mappings.record | length > 0
retries: 3
delay: 5

- name: Retrieve variable details in one query
servicenow.itsm.api_info:
resource: sc_item_option
sysparm_query: "sys_idIN{{ variable_mappings.record | map(attribute='sc_item_option.value') | join(',') }}"
columns: [item_option_new, value, sys_id]
register: variable_details
when: variable_mappings.record | length > 0

- name: Retrieve variable names using item_option_new IDs
servicenow.itsm.api_info:
resource: item_option_new
sysparm_query: "sys_idIN{{ variable_details.record | map(attribute='item_option_new.value') | join(',') }}"
columns: [sys_id, name]
register: variable_names
when: variable_details.record | length > 0

- name: Create dictionary of variable names by sys_id
ansible.builtin.set_fact:
variable_name_dict: "{{ dict(variable_names.record | map(attribute='sys_id') | zip(variable_names.record | map(attribute='name'))) }}"
cacheable: true
when: variable_names.record | length > 0

- name: Combine mappings with variable details
ansible.builtin.set_fact:
variable_combined: >-
{{
variable_details.record | map(
'combine', {
'request_item': (variable_mappings.record | selectattr('sc_item_option.value', 'equalto', item.sys_id) | map(attribute='request_item.value') | first)

Check warning on line 58 in roles/servicenow_ritm_retrieve_eda/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

yaml[line-length]

Line too long (161 > 160 characters)
}
) | list
}}
loop: "{{ variable_details.record }}"
loop_control:
label: "{{ item.sys_id }}"
when: variable_details.record | length > 0

- name: Combine variable names and values grouped by RITM
ansible.builtin.set_fact:
ritm_variables: >-
{{
ritm_variables | default({}) | combine({
item.request_item: (ritm_variables[item.request_item] | default([])) + [{
'name': variable_name_dict[item.item_option_new.value],
'value': item.value
}]
})
}}
loop: "{{ variable_combined }}"
loop_control:
label: "{{ item.item_option_new.value }}"
when: variable_combined | length > 0

- name: Build enriched_event structure with initial data
ansible.builtin.set_fact:
enriched_event: >-
{{
{
'req_sys_id': req_sys_id | default('Unknown Request ID'),
'ritm_details': ritm_details | default([]),
'ritm_variables': ritm_variables | default({}),
}
}}
- name: Nest RITM variables into RITM details
ansible.builtin.set_fact:
enriched_event: >-
{{
enriched_event | combine({
'ritm_details': enriched_event.ritm_details | map(
'combine', {
'variables': enriched_event.ritm_variables[item.sys_id.value] | default([])
}
) | list
})
}}
loop: "{{ enriched_event.ritm_details }}"
loop_control:
label: "{{ item.sys_id.value }}"

- name: Consolidate all facts and original event into set_stats
ansible.builtin.set_stats:
data:
enriched_event: "{{ enriched_event }}"
original_event: "{{ ansible_eda.event | default({}) }}"

- name: Display consolidated enriched_event
ansible.builtin.debug:
var: enriched_event

0 comments on commit 5ad43a9

Please sign in to comment.