added wrapper for fail_json and exit_json

Dieser Commit ist enthalten in:
Sebastian Tobie 2024-03-16 10:04:38 +01:00
Ursprung 85880d2867
Commit 84eb37ffa7
2 geänderte Dateien mit 11 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -2,3 +2,4 @@
minor_changes: minor_changes:
- Added an type hint to the update_doc function - Added an type hint to the update_doc function
- Added Type hint to the dictionary argument of the diff method - Added Type hint to the dictionary argument of the diff method
- added an wrapper for fail_json and exit_json

Datei anzeigen

@ -168,12 +168,8 @@ class AnsibleModule(object):
except Exception as exc: except Exception as exc:
import traceback import traceback
self.module.fail_json( self.fail("".join(traceback.format_exception(type(exc), exc, exc.__traceback__)))
"".join(traceback.format_exception(type(exc), exc, exc.__traceback__)), self.exit()
**self.result,
)
self.module.exit_json(**self.result)
raise Exception("exit_json failed")
@classmethod @classmethod
def doc(cls) -> str: def doc(cls) -> str:
@ -205,6 +201,14 @@ class AnsibleModule(object):
) )
) )
def fail(self, message: str) -> NoReturn:
"""Wrapper for AnsibleModule.fail_json"""
self.module.fail_json(message, **self.result)
def exit(self) -> NoReturn:
"""Wrapper for AnsibleModule.exit_json"""
self.module.exit_json(**self.result)
class SystemdUnitModule(AnsibleModule): class SystemdUnitModule(AnsibleModule):
#: path of the unitfile managed by this module #: path of the unitfile managed by this module