Skip to content

Instantly share code, notes, and snippets.

@pepoluan
Last active March 16, 2026 10:38
Show Gist options
  • Select an option

  • Save pepoluan/705fe22d33672ee4efb984c99e098b3f to your computer and use it in GitHub Desktop.

Select an option

Save pepoluan/705fe22d33672ee4efb984c99e098b3f to your computer and use it in GitHub Desktop.
Simple custom SaltStack state to return a message
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
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