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
297
299
298
attachment_client .delete_attached_records (
300
299
cmdb_table ,
@@ -324,6 +323,7 @@ def build_payload(module, table_client):
324
323
325
324
326
325
def ensure_present (module , table_client , attachment_client ):
326
+ cmdb_table = module .params ["sys_class_name" ] or "cmdb_ci"
327
327
mapper = get_mapper (module , "configuration_item_mapping" , PAYLOAD_FIELDS_MAPPING )
328
328
query_sys_id = utils .filter_dict (module .params , "sys_id" )
329
329
query_name = utils .filter_dict (module .params , "name" )
@@ -333,10 +333,9 @@ def ensure_present(module, table_client, attachment_client):
333
333
)
334
334
335
335
if not query_sys_id :
336
- configuration_item = table_client .get_record ("cmdb_ci" , query_name )
336
+ configuration_item = table_client .get_record (cmdb_table , query_name )
337
337
# User did not specify existing CI, so we need to create a new one.
338
338
if not configuration_item :
339
- cmdb_table = module .params ["sys_class_name" ] or "cmdb_ci"
340
339
new = mapper .to_ansible (
341
340
table_client .create_record (
342
341
cmdb_table , mapper .to_snow (payload ), module .check_mode
@@ -360,19 +359,9 @@ def ensure_present(module, table_client, attachment_client):
360
359
else :
361
360
# Get existing record using provided sys_id
362
361
old = mapper .to_ansible (
363
- table_client .get_record ("cmdb_ci" , query_sys_id , must_exist = True )
362
+ table_client .get_record (cmdb_table , query_sys_id , must_exist = True )
364
363
)
365
- # Check if provided name already exists
366
- if query_name :
367
- configuration_item = table_client .get_record ("cmdb_ci" , query_name )
368
- if configuration_item :
369
- old2 = mapper .to_ansible (configuration_item )
370
- if old ["sys_id" ] != old2 ["sys_id" ]:
371
- raise errors .ServiceNowError (
372
- "Record with the name {0} already exists." .format (
373
- module .params ["name" ]
374
- )
375
- )
364
+
376
365
# Update existing record
377
366
cmdb_table = old ["sys_class_name" ]
378
367
# If necessary, fetch the record from the table for the extended CI class
0 commit comments