Passing command line args to the RunnerClient API

373 views
Skip to first unread message

Drew Malone

unread,
Apr 4, 2017, 3:50:45 PM4/4/17
to salt-users
Hello!

I'm struggling with using the RunnerClient Python API to run an orchestrate job while also passing in 'normal' command line parameters.

Here's an equivalent command-line version of what I'm trying to do:

salt-run state.orch service.orchestrate --config_dir=/tmp/workspace --out=json

I can put together a RunnerClient and fire the orchestrate command easily enough:

master_opts = salt.config.client_config('/etc/salt/master')
master_opts['quiet'] = True
runner = salt.runner.RunnerClient(master_opts)
result = runner.cmd(fun='state.orch', arg=['service.orchestrate'] )

This works. However, when I try to introduce a command-line argument via the kwarg parameter:

result = runner.cmd(fun='state.orch', arg=['service.orchestrate'], kwarg={'config_dir':'/tmp/workspace', 'out':'json'} )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/salt/runner.py", line 130, in cmd
    print_event)
  File "/usr/lib/python2.7/site-packages/salt/client/mixins.py", line 226, in cmd
    self.functions[fun], arglist, pub_data
  File "/usr/lib/python2.7/site-packages/salt/minion.py", line 347, in load_args_and_kwargs
    else:
  File "/usr/lib/python2.7/site-packages/salt/utils/__init__.py", line 2979, in invalid_kwargs
    raise SaltInvocationError(msg)
salt.exceptions.SaltInvocationError: The following keyword arguments are not valid: config_dir=/tmp/1b0d6163fdc2-0, out=json


It looks like Salt is rejecting this because 'config_dir' and 'out' are not valid kwargs for 'state.orch'. I agree that they're not but my intention is to pass them to the salt-runner, not the function. 

What do I need to do in order to pass 'command line' arguments to a RunnerClient?

Thanks in advance!

- Drew

Daniel Wallace

unread,
Apr 4, 2017, 4:46:46 PM4/4/17
to Salt-users
You cannot pass them like that.

Anything that is a flag on the commandline is actually going to modify the opts that the runner uses.

When you instantiate the runnerclient, you can pass `opts` to it.


Modify the opts that make the changes you want to see in the output.  You can check salt.utils.parser to see which opts are modified by the different flags.

Daniel

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/CA%2BjBGJGEJPPx2ZoT%3DMdZdT1sHtPLe_c2Q2p1KjafE%3DfM991-0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Drew Malone

unread,
Apr 11, 2017, 10:43:07 AM4/11/17
to Salt-users
Ah! Thanks Daniel. That worked. 

Also many thanks for the salt.utils.parser. I was wondering where to go for that lookup.

- Drew
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages