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:
parent
ccb6b39f45
commit
5be37018a2
2 changed files with 57 additions and 49 deletions
|
@ -109,6 +109,13 @@ options:
|
||||||
- "Enable or disable power management of the host."
|
- "Enable or disable power management of the host."
|
||||||
- "For more comprehensive setup of PM use C(ovirt_host_pm) module."
|
- "For more comprehensive setup of PM use C(ovirt_host_pm) module."
|
||||||
version_added: 2.4
|
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:
|
iscsi:
|
||||||
description:
|
description:
|
||||||
- "If C(state) is I(iscsidiscover) it means that the iscsi attribute is being
|
- "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,
|
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):
|
def post_reinstall(self, host):
|
||||||
wait(
|
wait(
|
||||||
service=self._service.service(host.id),
|
service=self._service.service(host.id),
|
||||||
|
@ -382,6 +383,7 @@ def main():
|
||||||
kernel_params=dict(default=None, type='list'),
|
kernel_params=dict(default=None, type='list'),
|
||||||
hosted_engine=dict(default=None, choices=['deploy', 'undeploy']),
|
hosted_engine=dict(default=None, choices=['deploy', 'undeploy']),
|
||||||
power_management_enabled=dict(default=None, type='bool'),
|
power_management_enabled=dict(default=None, type='bool'),
|
||||||
|
activate=dict(default=True, type='bool'),
|
||||||
iscsi=dict(default=None, type='dict'),
|
iscsi=dict(default=None, type='dict'),
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -407,17 +409,20 @@ def main():
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
host = control_state(hosts_module)
|
host = control_state(hosts_module)
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
hosts_module.create(
|
ret = hosts_module.create(
|
||||||
deploy_hosted_engine=(
|
deploy_hosted_engine=(
|
||||||
module.params.get('hosted_engine') == 'deploy'
|
module.params.get('hosted_engine') == 'deploy'
|
||||||
) if module.params.get('hosted_engine') is not None else None,
|
) 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,
|
||||||
)
|
)
|
||||||
ret = hosts_module.action(
|
if module.params['activate'] and host is not None:
|
||||||
action='activate',
|
ret = hosts_module.action(
|
||||||
action_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
action='activate',
|
||||||
wait_condition=lambda h: h.status == hoststate.UP,
|
action_condition=lambda h: h.status != hoststate.UP,
|
||||||
fail_condition=failed_state,
|
wait_condition=lambda h: h.status == hoststate.UP,
|
||||||
)
|
fail_condition=failed_state,
|
||||||
|
)
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
ret = hosts_module.remove()
|
ret = hosts_module.remove()
|
||||||
elif state == 'maintenance':
|
elif state == 'maintenance':
|
||||||
|
|
|
@ -1182,7 +1182,7 @@ def main():
|
||||||
vm = vms_module.search_entity()
|
vm = vms_module.search_entity()
|
||||||
|
|
||||||
control_state(vm, vms_service, module)
|
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']:
|
if module.params['xen'] or module.params['kvm'] or module.params['vmware']:
|
||||||
vms_module.changed = import_vm(module, connection)
|
vms_module.changed = import_vm(module, connection)
|
||||||
|
|
||||||
|
@ -1200,46 +1200,49 @@ def main():
|
||||||
clone=module.params['clone'],
|
clone=module.params['clone'],
|
||||||
clone_permissions=module.params['clone_permissions'],
|
clone_permissions=module.params['clone_permissions'],
|
||||||
)
|
)
|
||||||
initialization = _get_initialization(sysprep, cloud_init, cloud_init_nics)
|
|
||||||
ret = vms_module.action(
|
# Run the VM if it was just created, else don't run it:
|
||||||
action='start',
|
if state == 'running' or vm is None:
|
||||||
post_action=vms_module._post_start_action,
|
initialization = _get_initialization(sysprep, cloud_init, cloud_init_nics)
|
||||||
action_condition=lambda vm: (
|
ret = vms_module.action(
|
||||||
vm.status not in [
|
action='start',
|
||||||
otypes.VmStatus.MIGRATING,
|
post_action=vms_module._post_start_action,
|
||||||
otypes.VmStatus.POWERING_UP,
|
action_condition=lambda vm: (
|
||||||
otypes.VmStatus.REBOOT_IN_PROGRESS,
|
vm.status not in [
|
||||||
otypes.VmStatus.WAIT_FOR_LAUNCH,
|
otypes.VmStatus.MIGRATING,
|
||||||
otypes.VmStatus.UP,
|
otypes.VmStatus.POWERING_UP,
|
||||||
otypes.VmStatus.RESTORING_STATE,
|
otypes.VmStatus.REBOOT_IN_PROGRESS,
|
||||||
]
|
otypes.VmStatus.WAIT_FOR_LAUNCH,
|
||||||
),
|
otypes.VmStatus.UP,
|
||||||
wait_condition=lambda vm: vm.status == otypes.VmStatus.UP,
|
otypes.VmStatus.RESTORING_STATE,
|
||||||
# Start action kwargs:
|
]
|
||||||
use_cloud_init=cloud_init is not None or len(cloud_init_nics) > 0,
|
),
|
||||||
use_sysprep=sysprep is not None,
|
wait_condition=lambda vm: vm.status == otypes.VmStatus.UP,
|
||||||
vm=otypes.Vm(
|
# Start action kwargs:
|
||||||
placement_policy=otypes.VmPlacementPolicy(
|
use_cloud_init=cloud_init is not None or len(cloud_init_nics) > 0,
|
||||||
hosts=[otypes.Host(name=module.params['host'])]
|
use_sysprep=sysprep is not None,
|
||||||
) if module.params['host'] else None,
|
vm=otypes.Vm(
|
||||||
initialization=initialization,
|
placement_policy=otypes.VmPlacementPolicy(
|
||||||
os=otypes.OperatingSystem(
|
hosts=[otypes.Host(name=module.params['host'])]
|
||||||
cmdline=module.params.get('kernel_params'),
|
) if module.params['host'] else None,
|
||||||
initrd=module.params.get('initrd_path'),
|
initialization=initialization,
|
||||||
kernel=module.params.get('kernel_path'),
|
os=otypes.OperatingSystem(
|
||||||
|
cmdline=module.params.get('kernel_params'),
|
||||||
|
initrd=module.params.get('initrd_path'),
|
||||||
|
kernel=module.params.get('kernel_path'),
|
||||||
|
) if (
|
||||||
|
module.params.get('kernel_params')
|
||||||
|
or module.params.get('initrd_path')
|
||||||
|
or module.params.get('kernel_path')
|
||||||
|
) else None,
|
||||||
) if (
|
) if (
|
||||||
module.params.get('kernel_params')
|
module.params.get('kernel_params')
|
||||||
or module.params.get('initrd_path')
|
or module.params.get('initrd_path')
|
||||||
or module.params.get('kernel_path')
|
or module.params.get('kernel_path')
|
||||||
|
or module.params.get('host')
|
||||||
|
or initialization
|
||||||
) else None,
|
) else None,
|
||||||
) if (
|
)
|
||||||
module.params.get('kernel_params')
|
|
||||||
or module.params.get('initrd_path')
|
|
||||||
or module.params.get('kernel_path')
|
|
||||||
or module.params.get('host')
|
|
||||||
or initialization
|
|
||||||
) else None,
|
|
||||||
)
|
|
||||||
|
|
||||||
if state == 'next_run':
|
if state == 'next_run':
|
||||||
# Apply next run configuration, if needed:
|
# Apply next run configuration, if needed:
|
||||||
|
|
Loading…
Reference in a new issue