Skip to content

hpilo_boot: fix module failing when trying to power on an already powered-on server #9646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9646-hpilo-fix-idempotency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "hpilo_boot - add option to get an idempotent behavior while powering on server, resulting in success instead of failure when using ``state: boot_once`` option (https://github.com/ansible-collections/community.general/pull/9646)."
28 changes: 22 additions & 6 deletions plugins/modules/hpilo_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
default: TLSv1
type: str
choices: ["SSLv3", "SSLv23", "TLSv1", "TLSv1_1", "TLSv1_2"]
idempotent_boot_once:
description:
- "This option makes O(state=boot_once) succeed instead of failing when the server is already powered on."
type: bool
default: false
version_added: 10.6.0
requirements:
- python-hpilo
notes:
Expand Down Expand Up @@ -138,6 +144,7 @@ def main():
image=dict(type='str'),
state=dict(type='str', default='boot_once', choices=['boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot', 'poweroff']),
force=dict(type='bool', default=False),
idempotent_boot_once=dict(type='bool', default=False),
ssl_version=dict(type='str', default='TLSv1', choices=['SSLv3', 'SSLv23', 'TLSv1', 'TLSv1_1', 'TLSv1_2']),
)
)
Expand All @@ -152,6 +159,7 @@ def main():
image = module.params['image']
state = module.params['state']
force = module.params['force']
idempotent_boot_once = module.params['idempotent_boot_once']
ssl_version = getattr(hpilo.ssl, 'PROTOCOL_' + module.params.get('ssl_version').upper().replace('V', 'v'))

ilo = hpilo.Ilo(host, login=login, password=password, ssl_version=ssl_version)
Expand Down Expand Up @@ -187,13 +195,21 @@ def main():

power_status = ilo.get_host_power_status()

if not force and power_status == 'ON':
module.fail_json(msg='HP iLO (%s) reports that the server is already powered on !' % host)

if power_status == 'ON':
ilo.warm_boot_server()
# ilo.cold_boot_server()
changed = True
if not force and not idempotent_boot_once:
# module.deprecate(
# 'The failure of the module when the server is already powered on is being deprecated.'
# ' Please set the parameter "idempotent_boot_once=true" to start using the new behavior.',
# version='11.0.0',
# collection_name='community.general'
# )
module.fail_json(msg='HP iLO (%s) reports that the server is already powered on !' % host)
elif not force and idempotent_boot_once:
pass
elif force:
ilo.warm_boot_server()
# ilo.cold_boot_server()
changed = True
else:
ilo.press_pwr_btn()
# ilo.reset_server()
Expand Down