Skip to content
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

Problem: Handle ModuleSoftError in purge. #148

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from

Conversation

jiuka
Copy link
Contributor

@jiuka jiuka commented Jan 23, 2025

Modules

alias_purge

Version

latest

Ansible Version

OPNSense Version

24.7.11

OPNSense-Plugin Version

No response

Issue

When alias_purge tries to delete a referenced alias a ModuleSoftError is raised from the delete method.

def delete(self) -> None:
response = self.b.delete()
if 'in_use' in response:
self._error(
msg=f"Unable to delete alias '{self.p[self.FIELD_ID]}' as it is currently referenced!",
verification=False,
)
def _error(self, msg: str, verification: bool = True) -> None:
if (verification and self.fail_verify) or (not verification and self.fail_proc):
self.m.fail_json(msg)
else:
self.m.warn(msg)
raise ModuleSoftError

TASK [Purge used alias] *********************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.handler.ModuleSoftError
fatal: [localhost]: FAILED! => {"changed": false, "failed_when_result": true, "module_stderr": "Traceback (most recent call last):
  File \"/tmp/ansible-tmp-17301/AnsiballZ_alias_purge.py\", line 107, in <module>
    _ansiballz_main()
    ~~~~~~~~~~~~~~~^^
  File \"/tmp/ansible-tmp-17301/AnsiballZ_alias_purge.py\", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/tmp/ansible-tmp-17301/AnsiballZ_alias_purge.py\", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.ansibleguy.opnsense.plugins.modules.alias_purge', init_globals=dict(_module_fqn='ansible_collections.ansibleguy.opnsense.plugins.modules.alias_purge', _modlib_path=modlib_path),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     run_name='__main__', alter_sys=True)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"<frozen runpy>\", line 226, in run_module
  File \"<frozen runpy>\", line 98, in _run_module_code
  File \"<frozen runpy>\", line 88, in _run_code
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/alias_purge.py\", line 77, in <module>
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/alias_purge.py\", line 73, in main
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/modules/alias_purge.py\", line 66, in run_module
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/main/alias_purge.py\", line 80, in process
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/helper/purge.py\", line 21, in purge
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/main/alias.py\", line 122, in delete
  File \"/tmp/ansible_ansibleguy.opnsense.alias_purge_payload_mfg4z4iu/ansible_ansibleguy.opnsense.alias_purge_payload.zip/ansible_collections/ansibleguy/opnsense/plugins/module_utils/main/alias.py\", line 133, in _error
ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.handler.ModuleSoftError
", "module_stdout": "", "msg": "MODULE FAILURE: No start of json char found
See stdout/stderr for the exact error", "rc": 1}

Config Ansible

Config OPNSense

No response

Debug Output

Profiling Output

No response

purge_alias on a referenced alias crashes the module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant