diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py index 8b9167d1f56..e1563d4fb8a 100644 --- a/lib/ansible/module_utils/ovirt.py +++ b/lib/ansible/module_utils/ovirt.py @@ -581,29 +581,30 @@ class BaseModule(object): self.post_create(entity) self.changed = True - # Wait for the entity to be created and to be in the defined state: - entity_service = self._service.service(entity.id) + if not self._module.check_mode: + # Wait for the entity to be created and to be in the defined state: + entity_service = self._service.service(entity.id) - def state_condition(entity): - return entity + def state_condition(entity): + return entity - if result_state: + if result_state: - def state_condition(entity): - return entity and entity.status == result_state + def state_condition(entity): + return entity and entity.status == result_state - wait( - service=entity_service, - condition=state_condition, - fail_condition=fail_condition, - wait=self._module.params['wait'], - timeout=self._module.params['timeout'], - poll_interval=self._module.params['poll_interval'], - ) + wait( + service=entity_service, + condition=state_condition, + fail_condition=fail_condition, + wait=self._module.params['wait'], + timeout=self._module.params['timeout'], + poll_interval=self._module.params['poll_interval'], + ) return { 'changed': self.changed, - 'id': entity.id, + 'id': getattr(entity, 'id', None), type(entity).__name__.lower(): get_dict_of_struct( struct=entity, connection=self._connection, diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py index 0ba5fd7844f..5be363d8cd5 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py @@ -1933,8 +1933,11 @@ def main(): clone=module.params['clone'], clone_permissions=module.params['clone_permissions'], ) - vms_module.post_present(ret['id']) + # If VM is going to be created and check_mode is on, return now: + if module.check_mode and ret.get('id') is None: + module.exit_json(**ret) + vms_module.post_present(ret['id']) # Run the VM if it was just created, else don't run it: if state == 'running': initialization = vms_module.get_initialization()