Skip to content

Instantly share code, notes, and snippets.

@DazWorrall
Last active December 14, 2015 13:09
Show Gist options
  • Save DazWorrall/5091529 to your computer and use it in GitHub Desktop.
Save DazWorrall/5091529 to your computer and use it in GitHub Desktop.
Apply a salt state to the current machine using the internal api
import salt.config
opts = salt.config.minion_config('/tmp/foo') # Doesnt need to be present
opts['file_client'] = 'local' # I dont know if this is right. Not 'remote'
opts['cachedir'] = '/tmp/salt' # Needs to be writeable
d = {
'/tmp/bacon': {
'file': [
'directory',
{'mode': 777},
]
}
}
m = salt.minion.SMinion(opts)
print m.functions['state.high'](d)
# Outputs:
#{'file_|-/tmp/bacon_|-/tmp/bacon_|-directory': {'comment': 'Directory /tmp/bacon updated', '__run_num__': 0, 'changes': {'/tmp/bacon': 'New Dir', 'mode': '777'}, 'name': '/tmp/bacon', 'result': True}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment