salt icon indicating copy to clipboard operation
salt copied to clipboard

Question: How to call state.orchestrate from a runner

Open rvora opened this issue 11 years ago • 1 comments

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

rvora avatar Mar 25 '15 21:03 rvora

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.

rvora avatar Mar 25 '15 22:03 rvora