diff --git a/.ansible-sign/sha256sum.txt b/.ansible-sign/sha256sum.txt index 452523b..54a7506 100644 --- a/.ansible-sign/sha256sum.txt +++ b/.ansible-sign/sha256sum.txt @@ -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 @@ -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 diff --git a/.ansible-sign/sha256sum.txt.sig b/.ansible-sign/sha256sum.txt.sig index b8939e9..d273426 100644 --- a/.ansible-sign/sha256sum.txt.sig +++ b/.ansible-sign/sha256sum.txt.sig @@ -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----- diff --git a/ServiceNowEDARITM.yml b/ServiceNowEDARITM.yml new file mode 100644 index 0000000..153f043 --- /dev/null +++ b/ServiceNowEDARITM.yml @@ -0,0 +1,7 @@ +--- +- name: Retrieve RITM from EDA Trigger + hosts: localhost + gather_facts: false + + roles: + - servicenow_ritm_retrieve_eda diff --git a/roles/servicenow_ritm_retrieve_eda/tasks/main.yml b/roles/servicenow_ritm_retrieve_eda/tasks/main.yml new file mode 100644 index 0000000..e5886ac --- /dev/null +++ b/roles/servicenow_ritm_retrieve_eda/tasks/main.yml @@ -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) + } + ) | 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