From d7edd34ba465a86daff68a212b63060eaaef8598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryan=20Bada=C3=AF?= <43403063+ryanb74@users.noreply.github.com> Date: Thu, 10 Apr 2025 07:05:35 +0200 Subject: [PATCH] hpilo_boot: fix module failing when trying to power on an already powered-on server (#9646) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fix hpilo_boot.py module failing when trying to power on an already powered-on server For this module to be idempotent, it should be successful when trying to reach a power state which is already there. It was already the case for "poweroff", however when running the module with "boot_once" state, it was failing if the server was already powered_on, which is not an idempotent behavior * doc: Add changelog fragment * fix: add flag to run boot_once idempotently without breaking the previous behavior and add deprecation warning * doc: fix documentation fragment description * fix unwanted format changes seems like I had an older version of this module formatted differently or that I had a formatter that automatically ran on this file * fix linting errors Removed trailing whitespace line 164 * add missing dash in idempotent_boot_once parameter description * fix doc issue * Update changelogs/fragments/9646-hpilo-fix-idempotency.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Update plugins/modules/hpilo_boot.py Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Update changelogs/fragments/9646-hpilo-fix-idempotency.yml Co-authored-by: Felix Fontein * comment out module deprecation and change idempotent boot_once parameter description * Update plugins/modules/hpilo_boot.py * Update plugins/modules/hpilo_boot.py Co-authored-by: Felix Fontein --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Felix Fontein Co-authored-by: Ryan BADAƏ --- .../fragments/9646-hpilo-fix-idempotency.yml | 2 ++ plugins/modules/hpilo_boot.py | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/9646-hpilo-fix-idempotency.yml diff --git a/changelogs/fragments/9646-hpilo-fix-idempotency.yml b/changelogs/fragments/9646-hpilo-fix-idempotency.yml new file mode 100644 index 0000000000..074fce62fe --- /dev/null +++ b/changelogs/fragments/9646-hpilo-fix-idempotency.yml @@ -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)." diff --git a/plugins/modules/hpilo_boot.py b/plugins/modules/hpilo_boot.py index ecef60f66a..c3d14564d6 100644 --- a/plugins/modules/hpilo_boot.py +++ b/plugins/modules/hpilo_boot.py @@ -76,6 +76,12 @@ options: 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: @@ -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']), ) ) @@ -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) @@ -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()