Skip to content

Instantly share code, notes, and snippets.

@ryan-lane
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-lane/ba2ddab9138bb4783fe0 to your computer and use it in GitHub Desktop.
Save ryan-lane/ba2ddab9138bb4783fe0 to your computer and use it in GitHub Desktop.
Using __context__ in execution modules
def testme():
if not 'testme.testme' in __context__:
__context__['testme.testme'] = 1
else:
__context__['testme.testme'] = __context__['testme.testme'] + 1
return __context__['testme.testme']
[ERROR ] Could not cache minion ID: [Errno 2] No such file or directory: '.salt/etc/salt/minion_id'
[INFO ] Loading fresh modules for state activity
[INFO ] Running state [state1] at time 14:41:54.350770
[INFO ] Executing state testme.testme for state1
[INFO ] 1
[INFO ] No changes made for state1
[INFO ] Completed state [state1] at time 14:41:54.351910
[INFO ] Running state [state2] at time 14:41:54.352122
[INFO ] Executing state testme.testme for state2
[INFO ] 2
[INFO ] No changes made for state2
[INFO ] Completed state [state2] at time 14:41:54.353012
[INFO ] Running state [state3] at time 14:41:54.353181
[INFO ] Executing state testme.testme for state3
[INFO ] 3
[INFO ] No changes made for state3
[INFO ] Completed state [state3] at time 14:41:54.353998
local:
----------
ID: Test state1
Function: testme.testme
Name: state1
Result: None
Comment:
Changes:
----------
ID: Test state2
Function: testme.testme
Name: state2
Result: None
Comment:
Changes:
----------
ID: Test state3
Function: testme.testme
Name: state3
Result: None
Comment:
Changes:
Summary
------------
Succeeded: 0
Failed: 0
Not Run: 3
------------
Total: 3
# -*- coding: utf-8 -*-
import logging
log = logging.getLogger(__name__)
def __virtual__():
return 'testme'
def testme(name):
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
log.info(__salt__['testme.testme']())
return ret
Test state1:
testme.testme:
- name: state1
Test state2:
testme.testme:
- name: state2
Test state3:
testme.testme:
- name: state3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment