diff --git a/changelogs/fragments/59377-ovirt-vm-when-creating-fix.yml b/changelogs/fragments/59377-ovirt-vm-when-creating-fix.yml new file mode 100644 index 00000000000..30d2553fbcc --- /dev/null +++ b/changelogs/fragments/59377-ovirt-vm-when-creating-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - ovirt_vm - fix for module failure on creation (https://github.com/ansible/ansible/issues/59385) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py index 8fcdbbc8562..cd8027431ae 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py @@ -2288,6 +2288,8 @@ def main(): ) vm = vms_module.search_entity(list_params={'all_content': True}) + # Boolean variable to mark if vm existed before module was executed + vm_existed = True if vm else False control_state(vm, vms_service, module) if state in ('present', 'running', 'next_run'): if module.params['xen'] or module.params['kvm'] or module.params['vmware']: @@ -2372,7 +2374,8 @@ def main(): wait_condition=lambda vm: vm.status == otypes.VmStatus.UP, ) # Allow migrate vm when state present. - vms_module._migrate_vm(vm) + if vm_existed: + vms_module._migrate_vm(vm) ret['changed'] = vms_module.changed elif state == 'stopped': if module.params['xen'] or module.params['kvm'] or module.params['vmware']: