1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cloud: ovirt: present state shouldn't change state if not needed (#28214)

This PR fixes: https://github.com/ansible/ansible/issues/27382
This commit is contained in:
Ondra Machacek 2017-08-28 14:20:55 +02:00 committed by Ryan Brown
parent ccb6b39f45
commit 5be37018a2
2 changed files with 57 additions and 49 deletions

View file

@ -109,6 +109,13 @@ options:
- "Enable or disable power management of the host."
- "For more comprehensive setup of PM use C(ovirt_host_pm) module."
version_added: 2.4
activate:
description:
- "If C(state) is I(present) activate the host."
- "This parameter is good to disable, when you don't want to change
the state of host when using I(present) C(state)."
default: True
version_added: 2.4
iscsi:
description:
- "If C(state) is I(iscsidiscover) it means that the iscsi attribute is being
@ -295,12 +302,6 @@ class HostsModule(BaseModule):
wait_condition=lambda h: h.status == hoststate.MAINTENANCE,
)
def post_update(self, entity):
if entity.status != hoststate.UP and self.param('state') == 'present':
if not self._module.check_mode:
self._service.host_service(entity.id).activate()
self.changed = True
def post_reinstall(self, host):
wait(
service=self._service.service(host.id),
@ -382,6 +383,7 @@ def main():
kernel_params=dict(default=None, type='list'),
hosted_engine=dict(default=None, choices=['deploy', 'undeploy']),
power_management_enabled=dict(default=None, type='bool'),
activate=dict(default=True, type='bool'),
iscsi=dict(default=None, type='dict'),
)
module = AnsibleModule(
@ -407,14 +409,17 @@ def main():
state = module.params['state']
host = control_state(hosts_module)
if state == 'present':
hosts_module.create(
ret = hosts_module.create(
deploy_hosted_engine=(
module.params.get('hosted_engine') == 'deploy'
) if module.params.get('hosted_engine') is not None else None,
result_state=(lambda h: h.status == hoststate.UP) if host is None else None,
fail_condition=failed_state if host is None else lambda h: False,
)
if module.params['activate'] and host is not None:
ret = hosts_module.action(
action='activate',
action_condition=lambda h: h.status == hoststate.MAINTENANCE,
action_condition=lambda h: h.status != hoststate.UP,
wait_condition=lambda h: h.status == hoststate.UP,
fail_condition=failed_state,
)

View file

@ -1182,7 +1182,7 @@ def main():
vm = vms_module.search_entity()
control_state(vm, vms_service, module)
if state == 'present' or state == 'running' or state == 'next_run':
if state in ('present', 'running', 'next_run'):
if module.params['xen'] or module.params['kvm'] or module.params['vmware']:
vms_module.changed = import_vm(module, connection)
@ -1200,6 +1200,9 @@ def main():
clone=module.params['clone'],
clone_permissions=module.params['clone_permissions'],
)
# Run the VM if it was just created, else don't run it:
if state == 'running' or vm is None:
initialization = _get_initialization(sysprep, cloud_init, cloud_init_nics)
ret = vms_module.action(
action='start',