Import Into ServiceNow CMDB Via Ansible ServiceNow Collection
It seems these days that at least half of my customers are using SNOW as their ITSM, so I’m always looking for ways to automate against it. RedHat recently launched a new collection that works directly with SNOW. In V1 release is the ability to work with problems, incidents, change requests, and configuration items(which are your CMDB entries). Playing with the collection is nice, but I wanted to do something interesting, so I made a way to use it to import switches into the CMDB in a repeatable manner.
Video Demo
Files
All files can be found here in my public github repo. I’ll start with the template file I’m going to be importing into SNOW. This will more likely be a CSV or something of the like, and perhaps I’ll update this in the future, but for now it’s a simple YAML file:
In the file I’m adding the important bits like name, serial number, IP address, and make/model. I’m using the name as the key, so each will need to be unique in my environment. Believe it or not, The sys_id field is they key in the database, so the system will let me add the exact same device info 100 times if I want to…each having it’s own entry in the database. I always have unique device names, so I’m using that.
Next I’ll look at the main playbook:
I setup a few variables in the vars section, most notably, which CMDB these entries should live in.
Task 1 reads in the file that I’m going to be importing into the database “snow-col-config-template.yml”.
Task 2 reads all of the existing CMDB entries and saves them into the “all_config_items” variable.
The final task loops through each entry to import and calls a sub task. I do this because I need to have a loop with an inner loop, and this is the simplest way to accomplish it.
This is the sub task that’s called for each entry ready from the import file.
This file consists of two tasks.
Task 1 takes each switch at a time and checks to see if it already exists in the database. Again, I’m matching based on name. Now this module isn’t idempotent unfortunately, so when it finds a match, it will show changed each time it runs. This isn’t necessarily a bad thing, in fact it really won’t hurt anything, I’ve just become a fan of idempotent modules(so expect to see the orange “changed” output). The output of this run is saved as a variable.
Task 2 runs and checks the previously created variable and sees if there was a change made. If there was a change made, then I know that the record existed already, so do nothing. If the record didn’t exist, then this task will go ahead and create it. Since this module doesn’t support idempotency I have to check if it already exists, otherwise it will create multiple entries for the same device…and you’ll have a bad time.
Running The Automation In Ansible Automation Platform
To view the CMDB now before I do the run I follow these three steps:
Here’s the output from the launch:
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 | TASK [Include the file that will be imported into SNOW] ************************ ok: [localhost] TASK [Read all of the existing CMDB entries and save them to a variable] ******* ok: [localhost] TASK [Loop to import devices. This calls a sub task for processing] *********** included: /tmp/awx_1056_3rnj557y/project/snow-col-config-import-sub.yml for localhost included: /tmp/awx_1056_3rnj557y/project/snow-col-config-import-sub.yml for localhost included: /tmp/awx_1056_3rnj557y/project/snow-col-config-import-sub.yml for localhost included: /tmp/awx_1056_3rnj557y/project/snow-col-config-import-sub.yml for localhost TASK [If sw1 already exists, update it's configuration] ************************ changed: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:44', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '1st lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '111', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '48af32ba07102010d42af03c7c1ed03b', 'skip_sync': 'false', 'device_type': 'switch', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:36:58', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000611', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw1', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '145f7e7a07102010d42af03c7c1ed06f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.51', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:48', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '2nd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '222', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '0d81877607102010d42af03c7c1ed0e9', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:45:14', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000612', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw2', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '5a61877607102010d42af03c7c1ed0f3', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.52', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-21 17:44:42', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '3rd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '333', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '514aea5f07632010d42af03c7c1ed010', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2021-04-21 17:44:42', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000613', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw3', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '954aea5f07632010d42af03c7c1ed00f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '0', 'monitor': 'false', 'ip_address': '192.168.51.53', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) TASK [sw1 didn't already exist, so create it] ********************************** skipping: [localhost] TASK [If sw2 already exists, update it's configuration] ************************ skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:44', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '1st lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '111', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '48af32ba07102010d42af03c7c1ed03b', 'skip_sync': 'false', 'device_type': 'switch', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:36:58', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000611', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw1', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '145f7e7a07102010d42af03c7c1ed06f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.51', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) changed: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:48', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '2nd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '222', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '0d81877607102010d42af03c7c1ed0e9', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:45:14', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000612', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw2', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '5a61877607102010d42af03c7c1ed0f3', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.52', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-21 17:44:42', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '3rd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '333', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '514aea5f07632010d42af03c7c1ed010', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2021-04-21 17:44:42', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000613', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw3', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '954aea5f07632010d42af03c7c1ed00f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '0', 'monitor': 'false', 'ip_address': '192.168.51.53', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) TASK [sw2 didn't already exist, so create it] ********************************** skipping: [localhost] TASK [If sw3 already exists, update it's configuration] ************************ skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:44', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '1st lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '111', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '48af32ba07102010d42af03c7c1ed03b', 'skip_sync': 'false', 'device_type': 'switch', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:36:58', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000611', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw1', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '145f7e7a07102010d42af03c7c1ed06f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.51', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:48', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '2nd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '222', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '0d81877607102010d42af03c7c1ed0e9', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:45:14', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000612', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw2', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '5a61877607102010d42af03c7c1ed0f3', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.52', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) changed: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-21 17:44:42', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '3rd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '333', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '514aea5f07632010d42af03c7c1ed010', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2021-04-21 17:44:42', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000613', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw3', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '954aea5f07632010d42af03c7c1ed00f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '0', 'monitor': 'false', 'ip_address': '192.168.51.53', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) TASK [sw3 didn't already exist, so create it] ********************************** skipping: [localhost] TASK [If sw4 already exists, update it's configuration] ************************ skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:44', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '1st lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '111', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '48af32ba07102010d42af03c7c1ed03b', 'skip_sync': 'false', 'device_type': 'switch', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:36:58', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000611', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw1', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '145f7e7a07102010d42af03c7c1ed06f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.51', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-22 14:08:48', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '2nd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '222', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '0d81877607102010d42af03c7c1ed0e9', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2020-11-09 16:45:14', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000612', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw2', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '5a61877607102010d42af03c7c1ed0f3', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '1', 'monitor': 'false', 'ip_address': '192.168.51.52', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) skipping: [localhost] => (item={'attested_date': '', 'can_switch': 'false', 'stack': 'false', 'operational_status': 'operational', 'cpu_manufacturer': '', 'sys_updated_on': '2021-04-21 17:44:42', 'discovery_source': '', 'first_discovered': '', 'due_in': '', 'can_partitionvlans': 'false', 'gl_account': '', 'invoice_number': '', 'sys_created_by': 'admin', 'ram': '', 'warranty_expiration': '', 'cpu_speed': '', 'owned_by': '', 'checked_out': '', 'firmware_manufacturer': '', 'disk_space': '', 'sys_domain_path': '/', 'discovery_proto_id': '', 'maintenance_schedule': '', 'cost_center': '', 'attested_by': '', 'dns_domain': '', 'assigned': '', 'purchase_date': '', 'short_description': '3rd lab switch', 'managed_by': '', 'range': '', 'firmware_version': '', 'can_print': 'false', 'last_discovered': '', 'ports': '', 'sys_class_name': 'cmdb_ci_ip_switch', 'cpu_count': '1', 'manufacturer': 'b7e831bdc0a80169015ae101f3c4d6cd', 'vendor': '', 'can_route': 'false', 'model_number': '3550', 'assigned_to': '', 'start_date': '', 'bandwidth': '', 'serial_number': '333', 'support_group': '', 'correlation_id': '', 'unverified': 'false', 'attributes': '', 'asset': '514aea5f07632010d42af03c7c1ed010', 'skip_sync': 'false', 'device_type': '', 'attestation_score': '', 'sys_updated_by': 'admin', 'sys_created_on': '2021-04-21 17:44:42', 'cpu_type': '', 'sys_domain': 'global', 'install_date': '', 'asset_tag': 'P1000613', 'hardware_substatus': '', 'fqdn': '', 'stack_mode': '', 'change_control': '', 'internet_facing': 'true', 'physical_interface_count': '', 'delivery_date': '', 'hardware_status': 'installed', 'channels': '', 'install_status': 'installed', 'supported_by': '', 'name': 'sw3', 'subcategory': 'IP', 'default_gateway': '', 'assignment_group': '', 'managed_by_group': '', 'can_hub': 'false', 'sys_id': '954aea5f07632010d42af03c7c1ed00f', 'po_number': '', 'checked_in': '', 'sys_class_path': '/!!/!2/!!/!,', 'mac_address': '', 'company': '', 'justification': '', 'department': '', 'snmp_sys_location': '', 'comments': '', 'cost': '', 'sys_mod_count': '0', 'monitor': 'false', 'ip_address': '192.168.51.53', 'model_id': '80af727a07102010d42af03c7c1ed0e3', 'duplicate_of': '', 'sys_tags': '', 'cost_cc': 'USD', 'discovery_proto_type': '', 'order_date': '', 'schedule': '', 'environment': 'production', 'due': '', 'attested': 'false', 'location': '', 'category': 'Hardware', 'fault_count': '0', 'lease_id': ''}) TASK [sw4 didn't already exist, so create it] ********************************** changed: [localhost] PLAY RECAP ********************************************************************* localhost : ok=10 changed=4 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0 |
This doesn’t format super well, but you can see the changed options for each one.
Here’s the view after the run:
So my existing devices were updated and new devices were added.
Conclusion
So this isn’t earth shattering, but could be useful if you need to do a one-time or perhaps a regular CMDB update/sync from another system. AAP could pull the CMDB entries from one system, then push them into SNOW. Let me know if you have any questions or comments and happy automating.