18
18
- Tadej Borovsak (@tadeboro)
19
19
- Matej Pevec (@mysteriouswolf)
20
20
- Polona Mihalič (@PolonaM)
21
+ - Mathijs de Ruiter (@EUCTechTopis)
21
22
22
23
short_description: Manage ServiceNow configuration items
23
24
289
290
def ensure_absent (module , table_client , attachment_client ):
290
291
mapper = get_mapper (module , "configuration_item_mapping" , PAYLOAD_FIELDS_MAPPING )
291
292
query = utils .filter_dict (module .params , "sys_id" , "name" )
292
- configuration_item = table_client .get_record ("cmdb_ci" , query )
293
+ cmdb_table = module .params ["sys_class_name" ] or "cmdb_ci"
294
+ configuration_item = table_client .get_record (cmdb_table , query )
293
295
294
296
if configuration_item :
295
- cmdb_table = configuration_item ["sys_class_name" ]
296
- if cmdb_table != "cmdb_ci" :
297
- configuration_item = table_client .get_record (cmdb_table , query )
298
-
299
297
attachment_client .delete_attached_records (
300
298
cmdb_table ,
301
299
configuration_item ["sys_id" ],
@@ -324,6 +322,7 @@ def build_payload(module, table_client):
324
322
325
323
326
324
def ensure_present (module , table_client , attachment_client ):
325
+ cmdb_table = module .params ["sys_class_name" ] or "cmdb_ci"
327
326
mapper = get_mapper (module , "configuration_item_mapping" , PAYLOAD_FIELDS_MAPPING )
328
327
query_sys_id = utils .filter_dict (module .params , "sys_id" )
329
328
query_name = utils .filter_dict (module .params , "name" )
@@ -333,10 +332,9 @@ def ensure_present(module, table_client, attachment_client):
333
332
)
334
333
335
334
if not query_sys_id :
336
- configuration_item = table_client .get_record ("cmdb_ci" , query_name )
335
+ configuration_item = table_client .get_record (cmdb_table , query_name )
337
336
# User did not specify existing CI, so we need to create a new one.
338
337
if not configuration_item :
339
- cmdb_table = module .params ["sys_class_name" ] or "cmdb_ci"
340
338
new = mapper .to_ansible (
341
339
table_client .create_record (
342
340
cmdb_table , mapper .to_snow (payload ), module .check_mode
@@ -360,11 +358,13 @@ def ensure_present(module, table_client, attachment_client):
360
358
else :
361
359
# Get existing record using provided sys_id
362
360
old = mapper .to_ansible (
363
- table_client .get_record ("cmdb_ci" , query_sys_id , must_exist = True )
361
+ table_client .get_record (cmdb_table , query_sys_id , must_exist = True )
364
362
)
365
363
# Check if provided name already exists
366
364
if query_name :
367
- configuration_item = table_client .get_record ("cmdb_ci" , query_name )
365
+ configuration_item = table_client .get_record (
366
+ old ["sys_class_name" ], query_name
367
+ )
368
368
if configuration_item :
369
369
old2 = mapper .to_ansible (configuration_item )
370
370
if old ["sys_id" ] != old2 ["sys_id" ]:
@@ -373,6 +373,7 @@ def ensure_present(module, table_client, attachment_client):
373
373
module .params ["name" ]
374
374
)
375
375
)
376
+
376
377
# Update existing record
377
378
cmdb_table = old ["sys_class_name" ]
378
379
# If necessary, fetch the record from the table for the extended CI class
0 commit comments