diff --git a/changelogs/fragments/ovirt_host_pm_bug_fixes_for_power_management.yaml b/changelogs/fragments/ovirt_host_pm_bug_fixes_for_power_management.yaml new file mode 100644 index 00000000000..279ffc4e51e --- /dev/null +++ b/changelogs/fragments/ovirt_host_pm_bug_fixes_for_power_management.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ovirt_host_pm - Bug fixes for power management (https://github.com/ansible/ansible/pull/47659). diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py b/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py index 6f9fae08967..cbea3201a7f 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py @@ -144,7 +144,13 @@ class HostModule(BaseModule): class HostPmModule(BaseModule): + def pre_create(self, entity): + # Save the entity, so we know if Agent already existed + self.entity = entity + def build_entity(self): + last = next((s for s in sorted([a.order for a in self._service.list()])), 0) + order = self.param('order') if self.param('order') is not None else self.entity.order if self.entity else last + 1 return otypes.Agent( address=self._module.params['address'], encrypt_options=self._module.params['encrypt_options'], @@ -158,14 +164,23 @@ class HostPmModule(BaseModule): port=self._module.params['port'], type=self._module.params['type'], username=self._module.params['username'], - order=self._module.params.get('order', 100), + order=order, ) def update_check(self, entity): + def check_options(): + if self.param('options'): + current = [] + if entity.options: + current = [(opt.name, str(opt.value)) for opt in entity.options] + passed = [(k, str(v)) for k, v in self.param('options').items()] + return sorted(current) == sorted(passed) + return True + return ( + check_options() and equal(self._module.params.get('address'), entity.address) and equal(self._module.params.get('encrypt_options'), entity.encrypt_options) and - equal(self._module.params.get('password'), entity.password) and equal(self._module.params.get('username'), entity.username) and equal(self._module.params.get('port'), entity.port) and equal(self._module.params.get('type'), entity.type) and