salt
salt copied to clipboard
Question: How to call state.orchestrate from a runner
I am writing a custom runner:
/srv/salt/runner/custom.py
def fancy():
client = salt.client.LocalClient(__opts__['conf_file'])
high_ret = client.cmd_iter('*', 'state.highstate', expr_form='glob')
# .... do something with high_ret data ....
# here I want to call equivalent of "salt-run state.orchestrate foo.bar"
# how do I do this? The following gives a stacktrace, seems like you can't
# create a new RunnerClient from inside a RunnerClient
runner = salt.runner.RunnerClient(__opts__['conf_file'])
runner.cmd('state.orchestrate foo.bar')
File "/srv/salt/runners/foo.py", line 41, in _run_orchestrate
runner = salt.runner.RunnerClient(__opts__['conf_file'])
File "/usr/lib/python2.6/site-packages/salt/runner.py", line 47, in __init__
self.functions = salt.loader.runner(opts) # Must be self.functions for mixin to work correctly :-/
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 402, in runner
opts, 'runners', 'runner', ext_type_dirs='runner_dirs'
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 72, in _create_loader
ext_types = os.path.join(opts['extension_modules'], ext_type)
TypeError: string indices must be integers, not str
Never mind, I figured it out, changing from
runner = salt.runner.RunnerClient(__opts__['conf_file'])
runner.cmd('state.orchestrate foo.bar')
to
runner = salt.runner.RunnerClient(__opts__)
runner.cmd('state.orchestrate', ['foo.bar' ])
does the trick.