Last active
March 16, 2026 10:38
-
-
Save pepoluan/705fe22d33672ee4efb984c99e098b3f to your computer and use it in GitHub Desktop.
Simple custom SaltStack state to return a message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import annotations | |
| import logging | |
| from typing import TypedDict | |
| __virtualname__ = "customx" | |
| LOG = logging.getLogger(__name__) | |
| # Silence "variable not defined" linting warnings, also to allow mock | |
| if "__opts__" not in globals(): | |
| __opts__ = {} | |
| def __virtual__() -> bool | str: | |
| """ | |
| Determine whether to load this module | |
| :return: Returns the module name if this module is to be loaded | |
| """ | |
| return __virtualname__ | |
| class StateResult(TypedDict): | |
| """Dictionary that must be returned at state completion""" | |
| name: str | |
| changes: dict | |
| pchanges: dict | |
| result: bool | None | |
| comment: str | |
| # noinspection PyUnusedLocal | |
| def message(name: str, text: str, **kwargs) -> StateResult: # noqa: ARG001 | |
| changes = {"new": text} | |
| ret: StateResult = { | |
| "name": name, | |
| "changes": changes, | |
| "pchanges": changes, | |
| "result": True, | |
| "comment": text, | |
| } | |
| return ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Test Message: | |
| customx.message: | |
| - text: This is a custom message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment