Saltstack custom states

From wikinotes

If you find yourself doing very complex things with jinja, you might want to consider writing your own salt-state instead for readability. See the following links:


official docs
gh issue that helps explain

salt-call saltutil.sync_states  # refresh custom states

Using Salt Information

__grains__['os_family']             # access grain from minion
__states__['cmd.script'](...)       # call salt.states.*
__salt__['file.file_exists'](...)   # call salt.modules.*

# __pillar__  # ?


States themselves are very simple to write. The state is simply a function within the python module.

def write_hi_to_disk():
    retval = {
        'name': 'mymodule.print_hi',
        'result': True,
        'changes': {
            'console': {'old': '', 'new': 'hi'},
        'comment': 'printed hi',
    return retval