From 1d1812b1a567bab2fd73c253ea13888fd2318779 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Thu, 21 Jun 2018 15:18:32 +0200 Subject: [PATCH] ovirt_affinity_lables_facts: Raise error when host/vm not found --- .../modules/cloud/ovirt/ovirt_affinity_label_facts.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_affinity_label_facts.py b/lib/ansible/modules/cloud/ovirt/ovirt_affinity_label_facts.py index 038b1fc74ae..5d406daa9c6 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_affinity_label_facts.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_affinity_label_facts.py @@ -98,6 +98,7 @@ from ansible.module_utils.ovirt import ( create_connection, get_dict_of_struct, ovirt_facts_full_argument_spec, + search_by_name, ) @@ -127,6 +128,8 @@ def main(): ]) if module.params['host']: hosts_service = connection.system_service().hosts_service() + if search_by_name(hosts_service, module.params['host']) is None: + raise Exception("Host '%s' was not found." % module.params['host']) labels.extend([ label for label in all_labels @@ -135,6 +138,8 @@ def main(): ]) if module.params['vm']: vms_service = connection.system_service().vms_service() + if search_by_name(vms_service, module.params['vm']) is None: + raise Exception("Vm '%s' was not found." % module.params['vm']) labels.extend([ label for label in all_labels