From f65df9189e7a9b9f42a6f6196a462b687d890b66 Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Fri, 24 May 2019 13:24:29 +0200 Subject: [PATCH] kubevirt_vm: simplify previous change + update comments (#56897) --- lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py b/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py index c0efab5591..0fa6b0c31c 100644 --- a/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py +++ b/lib/ansible/modules/cloud/kubevirt/kubevirt_vm.py @@ -405,16 +405,18 @@ class KubeVirtVM(KubeVirtRawModule): if our_state != 'absent': self.params['state'] = k8s_state = 'present' + # Start with fetching the current object to make sure it exists + # If it does, but we end up not performing any operations on it, at least we'll be able to return + # its current contents as part of the final json self.client = self.get_api_client() self._kind_resource = self.find_supported_resource(kind) k8s_obj = self.get_resource(self._kind_resource) if not self.check_mode and not vm_spec_change and k8s_state != 'absent' and not k8s_obj: self.fail("It's impossible to create an empty VM or change state of a non-existent VM.") - # Changes in VM's spec or any changes to VMIs warrant a full CRUD, the latter because - # VMIs don't really have states to manage; they're either present or don't exist + # If there are (potential) changes to `spec:` or we want to delete the object, that warrants a full CRUD # Also check_mode always warrants a CRUD, as that'll produce a sane result - if vm_spec_change or (ephemeral and vm_spec_change) or k8s_state == 'absent' or self.check_mode: + if vm_spec_change or k8s_state == 'absent' or self.check_mode: definition = self.construct_definition(kind, our_state, ephemeral) result = self.execute_crud(kind, definition) changed = result['changed']