salt.modules.cmdmod

A module for shelling out

Keep in mind that this module is insecure, in that it can give whomever has access to the master root execution access to all salt minions

Members

exec_code

salt.modules.cmdmod.exec_code(lang, code, cwd=None)

Pass in two strings, the first naming the executable language, aka - python2, python3, ruby, perl, lua, etc. the second string containing the code you wish to execute. The stdout and stderr will be returned

CLI Example:

salt '*' cmd.exec_code ruby 'puts "cheese"'

has_exec

salt.modules.cmdmod.has_exec(cmd)

Returns true if the executable is available on the minion, false otherwise

CLI Example:

salt '*' cmd.has_exec cat

retcode

salt.modules.cmdmod.retcode(cmd, cwd=None, runas=None, shell='/bin/bash', env=())

Execute a shell command and return the command's return code.

CLI Example:

salt '*' cmd.retcode "file /bin/bash"

run

salt.modules.cmdmod.run(cmd, cwd=None, runas=None, shell='/bin/bash', env=())

Execute the passed command and return the output as a string

CLI Example:

salt '*' cmd.run "ls -l | awk '/foo/{print $2}'"

run_all

salt.modules.cmdmod.run_all(cmd, cwd=None, runas=None, shell='/bin/bash', env=())

Execute the passed command and return a dict of return data

CLI Example:

salt '*' cmd.run_all "ls -l | awk '/foo/{print $2}'"

run_stderr

salt.modules.cmdmod.run_stderr(cmd, cwd=None, runas=None, shell='/bin/bash', env=())

Execute a command and only return the standard error

CLI Example:

salt '*' cmd.run_stderr "ls -l | awk '/foo/{print $2}'"

run_stdout

salt.modules.cmdmod.run_stdout(cmd, cwd=None, runas=None, shell='/bin/bash', env=())

Execute a command, and only return the standard out

CLI Example:

salt '*' cmd.run_stdout "ls -l | awk '/foo/{print $2}'"

shell_grain

salt.modules.cmdmod.shell_grain()

Return the default shell to use on this system

which

salt.modules.cmdmod.which(cmd)

Returns the path of an executable available on the minion, None otherwise

CLI Example:

salt '*' cmd.which cat

which_bin

salt.modules.cmdmod.which_bin(cmds)

Returns the first command found in a list of commands

CLI Example:

salt '*' cmd.which_bin '[pip2, pip, pip-python]'

Parent topic

Table Of Contents

Previous topic

salt.modules.cluster

Next topic

salt.modules.cp