diff --git a/modules/vcd_vapp.py b/modules/vcd_vapp.py index 9f9219b..e9fa475 100644 --- a/modules/vcd_vapp.py +++ b/modules/vcd_vapp.py @@ -327,8 +327,11 @@ def instantiate(self): response['changed'] = False try: - self.vdc.get_vapp(vapp_name) + found = self.vdc.get_vapp(vapp_name) except EntityNotFoundException: + found = None + + if not found: create_vapp_task = self.vdc.instantiate_vapp( name=vapp_name, catalog=catalog_name, @@ -377,8 +380,11 @@ def create(self): response['changed'] = False try: - self.vdc.get_vapp(vapp_name) + found = self.vdc.get_vapp(vapp_name) except EntityNotFoundException: + found = None + + if not found: create_vapp_task = self.vdc.create_vapp( name=vapp_name, description=description, @@ -402,8 +408,11 @@ def delete(self): response['changed'] = False try: - self.vdc.get_vapp(vapp_name) + found = self.vdc.get_vapp(vapp_name) except EntityNotFoundException: + found = None + + if not found: response['warnings'] = "Vapp {} is not present.".format(vapp_name) else: delete_vapp_task = self.vdc.delete_vapp( diff --git a/modules/vcd_vapp_vm.py b/modules/vcd_vapp_vm.py index b98d6c2..05c9a9d 100644 --- a/modules/vcd_vapp_vm.py +++ b/modules/vcd_vapp_vm.py @@ -384,8 +384,11 @@ def add_vm(self): response['changed'] = False try: - self.get_vm() + found = self.get_vm() except EntityNotFoundException: + found = None + + if not found: spec = { 'source_vm_name': source_vm_name, 'vapp': source_vapp_resource,