-
Notifications
You must be signed in to change notification settings - Fork 9
/
ios-remove-from-snow-cmdb.yml
37 lines (33 loc) · 1.04 KB
/
ios-remove-from-snow-cmdb.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
- name: Remove Router from ServiceNow CMDB
hosts: ios
connection: network_cli
gather_facts: no
vars_files:
- ./credentials/servicenow-credentials.yml
- ./default_vars.yml
tasks:
- name: Retrieve all routers
servicenow.itsm.configuration_item_info:
instance:
host: "https://{{ SN_INSTANCE }}.service-now.com"
username: "{{ SN_USERNAME }}"
password: "{{ SN_PASSWORD }}"
sys_class_name: cmdb_ci_ip_router
register: result
- set_fact:
sys_id_query: "{{ result.records|json_query(query) }}"
vars:
serial_num: "{{ input_sn }}"
query: "[?serial_number=='{{ serial_num }}'].sys_id"
- name: Delete router if it is listed in the CMDB
servicenow.itsm.configuration_item:
instance:
host: "https://{{ SN_INSTANCE }}.service-now.com"
username: "{{ SN_USERNAME }}"
password: "{{ SN_PASSWORD }}"
sys_class_name: cmdb_ci_ip_router
sys_id: "{{sys_id_query[0]}}"
state: absent
register: cmdb_router
when: (sys_id_query|length > 0)