diff --git a/playbooks/inventory_workflow_manager.yml b/playbooks/inventory_workflow_manager.yml index 72bcc39d0..227367c1e 100644 --- a/playbooks/inventory_workflow_manager.yml +++ b/playbooks/inventory_workflow_manager.yml @@ -21,47 +21,47 @@ config_verify: true state: merged config: - - username: "{{item.username}}" - password: "{{item.password}}" - enable_password: "{{item.enable_password}}" - ip_address_list: "{{item.ip_address_list}}" - cli_transport: "{{item.cli_transport}}" - snmp_auth_passphrase: "{{item.snmp_auth_passphrase}}" - snmp_auth_protocol: "{{item.snmp_auth_protocol}}" - snmp_mode: "{{item.snmp_mode}}" - snmp_priv_passphrase: "{{item.snmp_priv_passphrase}}" - snmp_priv_protocol: "{{item.snmp_priv_protocol}}" - snmp_ro_community: "{{item.snmp_ro_community}}" - snmp_rw_community: "{{item.snmp_rw_community}}" - snmp_username: "{{item.snmp_username}}" - credential_update: "{{item.credential_update}}" - clean_config: "{{item.clean_config}}" - type: "{{item.type}}" - device_resync: "{{item.device_resync}}" - reboot_device: "{{item.reboot_device}}" - role: "{{item.role}}" - add_user_defined_field: - - name: Test123 - description: "Added first udf for testing" - value: "value123" - - name: Test321 - description: "Added second udf for testing" - value: "value321" - provision_wired_device: - - device_ip: "1.1.1.1" - site_name: "Global/USA/San Francisco/BGL_18/floor_pnp" - resync_retry_count: 200 - resync_interval: 2 - - device_ip: "2.2.2.2" - site_name: "Global/USA/San Francisco/BGL_18/floor_test" - resync_retry_count: 200 - resync_retry_interval: 2 - update_interface_details: - description: "{{item.update_interface_details.description}}" - interface_name: "{{item.interface_name}}" - export_device_list: - password: "{{item.export_device_list.password}}" - - with_items: "{{ device_details }}" - tags: - - inventory_device + - username: "{{item.username}}" + password: "{{item.password}}" + enable_password: "{{item.enable_password}}" + ip_address_list: "{{item.ip_address_list}}" + cli_transport: "{{item.cli_transport}}" + snmp_auth_passphrase: "{{item.snmp_auth_passphrase}}" + snmp_auth_protocol: "{{item.snmp_auth_protocol}}" + snmp_mode: "{{item.snmp_mode}}" + snmp_priv_passphrase: "{{item.snmp_priv_passphrase}}" + snmp_priv_protocol: "{{item.snmp_priv_protocol}}" + snmp_ro_community: "{{item.snmp_ro_community}}" + snmp_rw_community: "{{item.snmp_rw_community}}" + snmp_username: "{{item.snmp_username}}" + credential_update: "{{item.credential_update}}" + clean_config: "{{item.clean_config}}" + type: "{{item.type}}" + device_resync: "{{item.device_resync}}" + reboot_device: "{{item.reboot_device}}" + role: "{{item.role}}" + add_user_defined_field: + - name: Test123 + description: "Added first udf for testing" + value: "value123" + - name: Test321 + description: "Added second udf for testing" + value: "value321" + provision_wired_device: + - device_ip: "1.1.1.1" + site_name: "Global/USA/San Francisco/BGL_18/floor_pnp" + resync_retry_count: 200 + resync_interval: 2 + - device_ip: "2.2.2.2" + site_name: "Global/USA/San Francisco/BGL_18/floor_test" + resync_retry_count: 200 + resync_retry_interval: 2 + update_interface_details: + description: "{{item.update_interface_details.description}}" + interface_name: "{{item.interface_name}}" + export_device_list: + password: "{{item.export_device_list.password}}" + + with_items: "{{ device_details }}" + tags: + - inventory_device diff --git a/plugins/modules/inventory_workflow_manager.py b/plugins/modules/inventory_workflow_manager.py index e5085c987..5c25455ca 100644 --- a/plugins/modules/inventory_workflow_manager.py +++ b/plugins/modules/inventory_workflow_manager.py @@ -746,9 +746,10 @@ def __init__(self, module): self.deleted_devices, self.provisioned_device_deleted, self.no_device_to_delete = [], [], [] self.response_list, self.role_updated_list, self.device_role_name = [], [], [] self.udf_added, self.udf_deleted = [], [] - self.ip_address_for_update, self.updated_ip, self.update_device_ips = [], [], [] - self.output_file_name = [] - self.resync_successful_devices = [] + self.ip_address_for_update, self.updated_ip, self.update_device_ips = [], [], [] + self.output_file_name, self.device_not_exist = [], [] + self.resync_successful_devices, self.device_not_exist_to_resync = [], [] + def validate_input(self): """ Validate the fields provided in the playbook. @@ -3131,6 +3132,11 @@ def get_diff_merged(self, config): self.log(self.msg, "ERROR") return self + if self.config[0].get("device_resync"): + is_device_exists = self.is_device_exist_in_ccc(config['ip_address_list']) + if not is_device_exists: + self.device_not_exist_to_resync.append(config['ip_address_list']) + if self.config[0].get('update_interface_details'): device_to_update = self.get_device_ips_from_config_priority() device_exist = self.is_device_exist_for_update(device_to_update) @@ -3172,9 +3178,10 @@ def get_diff_merged(self, config): device_exist = self.is_device_exist_for_update(device_to_update) if not device_exist: + self.device_not_exist.append(device_to_update) self.msg = ("Unable to reboot device because the device(s) listed: {0} are not present in the" " Cisco Catalyst Center.").format(str(device_to_update)) - self.status = "failed" + self.status = "ok" self.result['response'] = self.msg self.log(self.msg, "ERROR") return self @@ -3229,7 +3236,10 @@ def get_diff_merged(self, config): device_params.pop('snmpPrivProtocol', None) device_to_add_in_ccc = device_params['ipAddress'] - self.mandatory_parameter(device_to_add_in_ccc).check_return_status() + + if not self.config[0].get("device_resync"): + self.mandatory_parameter(device_to_add_in_ccc).check_return_status() + try: response = self.dnac._exec( family="devices", @@ -4077,6 +4087,17 @@ def update_inventory_profile_messages(self): " operation").format("', '".join(self.no_device_to_delete)) result_msg_list_not_changed.append(deleted_devices) + if self.device_not_exist: + devices = ', '.join(map(str, self.device_not_exist)) + device_not_exist = ("Unable to reboot device because the device(s) listed: {0} are not present in the" + " Cisco Catalyst Center.").format(str(devices)) + result_msg_list_not_changed.append(device_not_exist) + + if self.device_not_exist_to_resync: + devices = ', '.join(map(str, self.device_not_exist_to_resync)) + device_not_exist = ("Unable to resync device because the device(s) listed: {0} are not present in the Cisco Catalyst Center.").format(str(devices)) + result_msg_list_not_changed.append(device_not_exist) + if self.response_list: response_list_for_update = "{0}".format(", ".join(self.response_list)) result_msg_list_changed.append(response_list_for_update)