diff --git a/plugins/module_utils/helper/system.py b/plugins/module_utils/helper/system.py index 63abd1e..432ca76 100644 --- a/plugins/module_utils/helper/system.py +++ b/plugins/module_utils/helper/system.py @@ -50,6 +50,14 @@ def wait_for_response(module: AnsibleModule) -> bool: raise TimeoutError +def get_upgrade_status(s: Session) -> dict: + return s.get({ + 'command': 'upgradestatus', + 'module': 'core', + 'controller': 'firmware', + }) + + def wait_for_update(module: AnsibleModule, s: Session) -> bool: timeout = time() + module.params['wait_timeout'] @@ -65,11 +73,7 @@ def wait_for_update(module: AnsibleModule, s: Session) -> bool: poll_interval_start = time() try: - result = s.get({ - 'command': 'upgradestatus', - 'module': 'core', - 'controller': 'firmware', - }) + result = get_upgrade_status(s) status = result['status'] _wait_msg(module, f"Got response: {status}") diff --git a/plugins/modules/system.py b/plugins/modules/system.py index 5c6d14e..07edb0a 100644 --- a/plugins/modules/system.py +++ b/plugins/modules/system.py @@ -15,7 +15,7 @@ from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.api import Session from ansible_collections.ansibleguy.opnsense.plugins.module_utils.defaults.main import OPN_MOD_ARGS from ansible_collections.ansibleguy.opnsense.plugins.module_utils.helper.system import wait_for_response, \ - wait_for_update + wait_for_update, get_upgrade_status except MODULE_EXCEPTIONS: module_dependency_error() @@ -59,6 +59,12 @@ def run_module(): if not module.check_mode: with Session(module=module) as s: + upgrade_status = get_upgrade_status(s) + if upgrade_status['status'] != 'done': + module.fail_json( + f'System may be upgrading! System-actions are currently blocked! Details: {upgrade_status}' + ) + s.post({ 'command': module.params['action'], 'module': 'core',