diff --git a/changelogs/fragments/vsphere_guest-corrected-state-operations.yml b/changelogs/fragments/vsphere_guest-corrected-state-operations.yml new file mode 100644 index 00000000000..ad34cae8b6a --- /dev/null +++ b/changelogs/fragments/vsphere_guest-corrected-state-operations.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - vsphere_guest - creating machines without vm_extra_config allowed + - vsphere_guest - powering on/off absent virtual machine will fail diff --git a/lib/ansible/modules/cloud/vmware/_vsphere_guest.py b/lib/ansible/modules/cloud/vmware/_vsphere_guest.py index ff23e6daef5..614da557c55 100644 --- a/lib/ansible/modules/cloud/vmware/_vsphere_guest.py +++ b/lib/ansible/modules/cloud/vmware/_vsphere_guest.py @@ -1904,9 +1904,8 @@ def main(): module.exit_json(changed=False, msg="vm %s not present" % guest) # check if user is trying to perform state operation on a vm which doesn't exists - elif state in ['present', 'powered_off', 'powered_on'] and not all((vm_extra_config, - vm_hardware, vm_disk, vm_nic, esxi)): - module.exit_json(changed=False, msg="vm %s not present" % guest) + elif state in ['present', 'powered_off', 'powered_on'] and not all((vm_hardware, vm_disk, vm_nic, esxi)): + module.fail_json(msg="vm %s not present and not all options neccessary to create are provided" % guest) # Create the VM elif state in ['present', 'powered_off', 'powered_on']: