diff --git a/changelogs/fragments/vmware_maintenance_mode_params.yaml b/changelogs/fragments/vmware_maintenance_mode_params.yaml new file mode 100644 index 00000000000..aa7750c004a --- /dev/null +++ b/changelogs/fragments/vmware_maintenance_mode_params.yaml @@ -0,0 +1,2 @@ +minor_changes: + - vmware_datastore_maintenancemode - Raise an error if the datastore does not exist. diff --git a/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py b/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py index a86d9cb31e1..7ad6d9f352f 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py +++ b/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py @@ -120,7 +120,10 @@ class VmwareDatastoreMaintenanceMgr(PyVmomi): datastore_cluster = self.params.get('datastore_cluster') self.datastore_objs = [] if datastore_name: - self.datastore_objs = [self.find_datastore_by_name(datastore_name=datastore_name)] + ds = self.find_datastore_by_name(datastore_name=datastore_name) + if not ds: + self.module.fail_json(msg='Failed to find datastore "%(datastore)s".' % self.params) + self.datastore_objs = [ds] elif cluster_name: cluster = find_cluster_by_name(self.content, cluster_name) if not cluster: