r/saltstack • u/tem102938 • Jan 13 '25
Reactor help with runners and custom modules
I made a simple custom module.
# cat /srv/salt/_modules/testmod.py
def myTestFunction(data):
with open('/tmp/test.txt', 'a') as mytest:
mytest.write('test')
mytest.close() I can execute it at the command line via a runner.
salt-run salt.cmd testmod.myTestFunction data=test I'd like to use Reactor to execute the that module via a runner when a Job event occurs.
# cat /etc/salt/master.d/reactor.conf
reactor:
- 'salt/job/*/ret': # Event triggered when a job completes
- /srv/reactor/testReactorCaller.sls
# cat /srv/reactor/testReactorCaller.sls
hsTest01:
runner.salt.cmd:
- args:
- name: testmod.myTestFunction
- data: {{ data }} This doesn't appear to do what I want. I think I'm not using the right syntax in my Reactoer file /srv/reactor/testReactorCaller.sls. Any suggestions? Thanks in advance for any help. Also, later, I would filter on the fun variable of the event. What that be best in the Reactor file with Jinja or in the custom module in python?
0
Upvotes
2
u/whytewolf01 Jan 14 '25
so first. salt.cmd is for execution modules. not runners. so you don't need runner.salt.cmd. you can call your runner directly
next your tag match is missing info. ret for jobs has the minion id on the end of the ret.
'salt/job/*/ret/*'so you need the wildcard at the end to match any minion.and finally job events can be VERY busy. hopefully your runner is able to handle a lot of data very quickly. other wise it might overload.
https://docs.saltproject.io/en/3006/topics/reactor/index.html#runner-reactions https://docs.saltproject.io/en/latest/topics/event/master_events.html#job-events