neulab/tldr huggingface dataset:
config The configuration sent as text.
NOTE: This argument is ignored when config_path is specified.
config_path The absolute or remote path to the file with the configuration to be parsed. This argument supports the usual Salt filesystem URIs, e.g., salt://, https://, ftp://, s3://, etc.
regex  The regular expression to match the lines against.
saltenv: base Salt fileserver environment from which to retrieve the file. This argument is ignored when config_path is not a salt:// URL.
salt '*' ciscoconfparse.find_lines config_path=https://bit.ly/2mAdq7z regex='ip address'
cisco-ios-router: -  ip address dhcp -  ip address 172.20.0.1 255.255.255.0 -  no ip address
salt.modules.ciscoconfparse_mod.find_lines_w_child(config=None, config_path=None, parent_regex=None, child_regex=None, ignore_ws=False, saltenv='base') Return a list of parent lines (as text)  matching the regular expression parent_regex that have children lines matching child_regex.
parent_regex The regular expression to match the parent lines against.
child_regex The regular expression to match the child lines against.
ignore_ws: False Whether to ignore the white spaces.
salt '*' ciscoconfparse.find_lines_w_child config_path=https://bit.ly/2mAdq7z parent_line='line con' child_line='stopbits' salt '*' ciscoconfparse.find_lines_w_child config_path=https://bit.ly/2uIRxau parent_regex='ge-(.*)' child_regex='unit \d+'
salt.modules.ciscoconfparse_mod.find_lines_wo_child(config=None, config_path=None, parent_regex=None, child_regex=None, ignore_ws=False, saltenv='base') Return a list of parent ciscoconfparse.IOSCfgLine lines as text, which matched the parent_regex and whose children did not match child_regex.  Only the parent ciscoconfparse.IOSCfgLine text lines will be returned.  For simplicity, this method only finds oldest ancestors without immediate children that match.
salt '*' ciscoconfparse.find_lines_wo_child config_path=https://bit.ly/2mAdq7z parent_line='line con' child_line='stopbits'
salt.modules.ciscoconfparse_mod.find_objects(config=None, config_path=None, regex=None, saltenv='base') Return all the line objects that match the expression in the regex argument.
WARNING: This function is mostly valuable when invoked from other Salt components (i.e., execution modules, states, templates etc.). For CLI usage, please consider using ciscoconfparse.find_lines
Usage example:
objects = __salt__['ciscoconfparse.find_objects'](config_path='salt://path/to/config.txt', regex='Gigabit') for obj in objects: print(obj.text)
salt.modules.ciscoconfparse_mod.find_objects_w_child(config=None, config_path=None, parent_regex=None, child_regex=None, ignore_ws=False, saltenv='base') Parse through the children of all parent lines matching parent_regex, and return a list of child objects, which matched the child_regex.
WARNING: This function is mostly valuable when invoked from other Salt components (i.e., execution modules, states, templates etc.). For CLI usage, please consider using ciscoconfparse.find_lines_w_child
objects = __salt__['ciscoconfparse.find_objects_w_child'](config_path='https://bit.ly/2mAdq7z', parent_regex='line con', child_regex='stopbits') for obj in objects: print(obj.text)
salt.modules.ciscoconfparse_mod.find_objects_wo_child(config=None, config_path=None, parent_regex=None, child_regex=None, ignore_ws=False, saltenv='base') Return a list of parent ciscoconfparse.IOSCfgLine objects, which matched the parent_regex and whose children did not match child_regex.  Only the parent ciscoconfparse.IOSCfgLine objects will be returned. For simplicity, this method only finds oldest ancestors without immediate children that match.
WARNING: This function is mostly valuable when invoked from other Salt components (i.e., execution modules, states, templates etc.). For CLI usage, please consider using ciscoconfparse.find_lines_wo_child
objects = __salt__['ciscoconfparse.find_objects_wo_child'](config_path='https://bit.ly/2mAdq7z', parent_regex='line con', child_regex='stopbits') for obj in objects: print(obj.text)
salt.modules.cisconso Execution module for Cisco Network Services Orchestrator Proxy minions
For documentation on setting up the cisconso proxy minion look in the documentation for salt.proxy.cisconso.
salt.modules.cisconso.apply_rollback(datastore, name) Apply a system rollback
• datastore (DatastoreType (str enum).) -- The datastore, e.g. running, operational.  One of the NETCONF store IETF types
• name (str) -- an ID of the rollback to restore
salt cisco-nso cisconso.apply_rollback 52
salt.modules.cisconso.get_data(datastore, path) Get the configuration of the device tree at the given path
• path (list, str OR tuple) -- The device path to set the value at, a list of element names in order, / separated
Returns The network configuration at that tree
salt cisco-nso cisconso.get_data running 'devices/ex0'
salt.modules.cisconso.get_rollback(name) Get the backup of stored a configuration rollback
Parameters name (str) -- Typically an ID of the backup
Returns the contents of the rollback snapshot
salt cisco-nso cisconso.get_rollback 52
salt.modules.cisconso.get_rollbacks() Get a list of stored configuration rollbacks
salt cisco-nso cisconso.get_rollbacks
salt.modules.cisconso.info() Return system information for grains of the NSO proxy minion
salt '*' cisconso.info
salt.modules.cisconso.set_data_value(datastore, path, data) Set a data entry in a datastore
• data (dict) -- The new value at the given path
Returns True if successful, otherwise error.
salt cisco-nso cisconso.set_data_value running 'devices/ex0/routes' 10.0.0.20/24
salt.modules.cloud Salt-specific interface for calling Salt Cloud directly
salt.modules.cloud.action(fun=None, cloudmap=None, names=None, provider=None, instance=None, **kwargs) Execute a single action on the given provider/instance
salt minionname cloud.action start instance=myinstance salt minionname cloud.action stop instance=myinstance salt minionname cloud.action show_image provider=my-ec2-config image=ami-1624987f
salt.modules.cloud.create(provider, names, opts=None, **kwargs) Create an instance using Salt Cloud
salt minionname cloud.create my-ec2-config myinstance image=ami-1624987f size='t1.micro' ssh_username=ec2-user securitygroup=default delvol_on_destroy=True
salt.modules.cloud.destroy(names) Destroy the named VM(s)
salt minionname cloud.destroy myinstance
salt.modules.cloud.full_query(query_type='list_nodes_full') List all available cloud provider data
salt minionname cloud.full_query
salt.modules.cloud.get_instance(name, provider=None) Return details on an instance.
Similar to the cloud action show_instance but returns only the instance details.
salt minionname cloud.get_instance myinstance
SLS Example:
{{ salt['cloud.get_instance']('myinstance')['mac_address'] }}
salt.modules.cloud.has_instance(name, provider=None) Return true if the instance is found on a provider
salt minionname cloud.has_instance myinstance
salt.modules.cloud.list_images(provider='all') List cloud provider images for the given providers
salt minionname cloud.list_images my-gce-config
salt.modules.cloud.list_locations(provider='all') List cloud provider locations for the given providers
salt minionname cloud.list_locations my-gce-config
salt.modules.cloud.list_sizes(provider='all') List cloud provider sizes for the given providers
salt minionname cloud.list_sizes my-gce-config
salt.modules.cloud.map_run(path=None, **kwargs) Execute a salt cloud map file
Cloud Map data can be retrieved from several sources:
• a local file (provide the path to the file to the 'path' argument)
• a JSON-formatted map directly (provide the appropriately formatted to using the 'map_data' argument)
• the Salt Pillar (provide the map name of under 'pillar:cloud:maps' to the 'map_pillar' argument)
NOTE: Only one of these sources can be read at a time. The options are listed in their order of precedence.
salt minionname cloud.map_run /path/to/cloud.map salt minionname cloud.map_run path=/path/to/cloud.map salt minionname cloud.map_run map_pillar='<map_pillar>' .. versionchanged:: 2018.3.1 salt minionname cloud.map_run map_data='<actual map data>'
salt.modules.cloud.network_create(provider, names, **kwargs) Create private network
salt minionname cloud.network_create my-nova names=['salt'] cidr='192.168.100.0/24'
salt.modules.cloud.network_list(provider) List private networks
salt minionname cloud.network_list my-nova
salt.modules.cloud.profile_(profile, names, vm_overrides=None, opts=None, **kwargs) Spin up an instance using Salt Cloud
salt minionname cloud.profile my-gce-config myinstance
salt.modules.cloud.query(query_type='list_nodes') List cloud provider data for all providers
salt minionname cloud.query salt minionname cloud.query list_nodes_full salt minionname cloud.query list_nodes_select
salt.modules.cloud.select_query(query_type='list_nodes_select') List selected nodes
salt minionname cloud.select_query
salt.modules.cloud.virtual_interface_create(provider, names, **kwargs) Attach private interfaces to a server
salt minionname cloud.virtual_interface_create my-nova names=['salt-master'] net_name='salt'
salt.modules.cloud.virtual_interface_list(provider, names, **kwargs) List virtual interfaces on a server
salt minionname cloud.virtual_interface_list my-nova names=['salt-master']
salt.modules.cloud.volume_attach(provider, names, **kwargs) Attach volume to a server
salt minionname cloud.volume_attach my-nova myblock server_name=myserver device='/dev/xvdf'
salt.modules.cloud.volume_create(provider, names, **kwargs) Create volume
salt minionname cloud.volume_create my-nova myblock size=100 voltype=SSD
salt.modules.cloud.volume_delete(provider, names, **kwargs) Delete volume
salt minionname cloud.volume_delete my-nova myblock
salt.modules.cloud.volume_detach(provider, names, **kwargs) Detach volume from a server
salt minionname cloud.volume_detach my-nova myblock server_name=myserver
salt.modules.cloud.volume_list(provider) List block storage volumes
salt minionname cloud.volume_list my-nova
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.
salt.modules.cmdmod.exec_code(lang, code, cwd=None, args=None, **kwargs) 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 will be returned.
All parameters from cmd.run_all except python_shell can be used.
salt '*' cmd.exec_code ruby 'puts "cheese"' salt '*' cmd.exec_code ruby 'puts "cheese"' args='["arg1", "arg2"]' env='{"FOO": "bar"}'
salt.modules.cmdmod.exec_code_all(lang, code, cwd=None, args=None, **kwargs) 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. All cmd artifacts (stdout, stderr, retcode, pid) will be returned.
salt '*' cmd.exec_code_all ruby 'puts "cheese"' salt '*' cmd.exec_code_all ruby 'puts "cheese"' args='["arg1", "arg2"]' env='{"FOO": "bar"}'
salt.modules.cmdmod.has_exec(cmd) Returns true if the executable is available on the minion, false otherwise
salt '*' cmd.has_exec cat
salt.modules.cmdmod.powershell(cmd, cwd=None, stdin=None, runas=None, shell='powershell', env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, password=None, depth=None, encode_cmd=False, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute the passed PowerShell command and return the output as a dictionary.
Other cmd.* functions (besides cmd.powershell_all) return the raw text output of the command. This function appends | ConvertTo-JSON to the command and then parses the JSON into a Python dictionary. If you want the raw textual result of your PowerShell command you should use cmd.run with the shell=powershell option.
salt '*' cmd.run '$PSVersionTable.CLRVersion' shell=powershell salt '*' cmd.run 'Get-NetTCPConnection' shell=powershell
WARNING: This passes the cmd argument directly to PowerShell without any further processing! Be absolutely sure that you have properly sanitized the command passed to this function and do not use untrusted inputs.
In addition to the normal cmd.run parameters, this command offers the depth parameter to change the Windows default depth for the ConvertTo-JSON powershell command. The Windows default is 2. If you need more depth, set that here.
NOTE: For some commands, setting the depth to a value greater than 4 greatly increases the time it takes for the command to return and in many cases returns useless data.
• cmd (str) -- The powershell command to run.
• cwd (str) -- The directory from which to execute the command. Defaults to the home directory of the user specified by runas (or the user under which Salt is running if runas is not specified).
• stdin (str) -- A string of standard input can be specified for the command to be run using the stdin parameter. This can be useful in cases where sensitive information must be read from standard input.
• runas (str) -- Specify an alternate user to run the command. The default behavior is to run as the user under which Salt is running. If running on a Windows minion you must also use the password argument, and the target user account must be in the Administrators group.
• password (str) --
Windows only. Required when specifying runas. This parameter will be ignored on non-Windows platforms.
• shell (str) -- Specify an alternate shell. Defaults to "powershell". Can also use "pwsh" for powershell core if present on the system
• python_shell (bool) -- If False, let python handle the positional arguments. Set to True to use shell features, such as pipes or redirection.
• env (dict) --
Environment variables to be set prior to execution.
NOTE: When passing environment variables on the CLI, they should be passed as the string representation of a dictionary.
salt myminion cmd.powershell 'some command' env='{"FOO": "bar"}'
NOTE: When using environment variables on Window's, case-sensitivity matters, i.e. Window's uses Path as opposed to PATH for other systems.
• clean_env (bool) -- Attempt to clean out all other shell environment variables and set only those provided in the 'env' argument to this function.
• template (str) -- If this setting is applied then the named templating engine will be used to render the downloaded file. Currently jinja, mako, and wempy are supported.
• rstrip (bool) -- Strip all whitespace off the end of output before it is returned.
• umask (str) -- The umask (in octal) to use when running the command.
• output_encoding (str) --
Control the encoding used to decode the command's output.
NOTE: This should not need to be used in most cases. By default, Salt will try to use the encoding detected from the system locale, and will fall back to UTF-8 if this fails. This should only need to be used in cases where the output of the command is encoded in something other than the system locale or UTF-8.
To see the encoding Salt has detected from the system locale, check the locale line in the output of test.versions_report.
• output_loglevel (str) --
Control the loglevel at which the output from the command is logged to the minion log.
NOTE: The command being run will still be logged at the debug loglevel regardless, unless quiet is used for this value.
• ignore_retcode (bool) -- If the exit code of the command is nonzero, this is treated as an error condition, and the output from the command will be logged to the minion log. However, there are some cases where programs use the return code for signaling and a nonzero exit code doesn't necessarily mean failure. Pass this argument as True to skip logging the output if the command has a nonzero exit code.
• hide_output (bool) --
If True, suppress stdout and stderr in the return data.
NOTE: This is separate from output_loglevel, which only handles how Salt logs to the minion log.
• timeout (int) -- A timeout in seconds for the executed process to return.
• use_vt (bool) -- Use VT utils (saltstack) to stream the command output more interactively to the console and the logs. This is experimental.
• reset_system_locale (bool) -- Resets the system locale
• saltenv (str) -- The salt environment to use. Default is 'base'
• depth (int) --
The number of levels of contained objects to be included. Default is 2. Values greater than 4 seem to greatly increase the time it takes for the command to complete for some commands. eg: dir
• encode_cmd (bool) -- Encode the command before executing. Use in cases where characters may be dropped or incorrectly converted when executed.  Default is False.
• success_retcodes (list) -- .INDENT 2.0
This parameter will allow a list of non-zero return codes that should be considered a success.  If the return code returned from the run matches any in the provided list, the return code will be overridden with zero.
• success_stdout (list) -- .INDENT 2.0
This parameter will allow a list of strings that when found in standard out should be considered a success.  If stdout returned from the run matches any in the provided list, the return code will be overridden with zero.
• success_stderr (list) -- .INDENT 2.0
This parameter will allow a list of strings that when found in standard error should be considered a success.  If stderr returned from the run matches any in the provided list, the return code will be overridden with zero.
• stdin_raw_newlines (bool) -- .INDENT 2.0
False If True, Salt will not automatically convert the characters \n present in the stdin value to newlines.
dict   A dictionary of data returned by the powershell command.
salt '*' cmd.powershell "$PSVersionTable.CLRVersion"
salt.modules.cmdmod.powershell_all(cmd, cwd=None, stdin=None, runas=None, shell='powershell', env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', quiet=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, password=None, depth=None, encode_cmd=False, force_list=False, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute the passed PowerShell command and return a dictionary with a result field representing the output of the command, as well as other fields showing us what the PowerShell invocation wrote to stderr, the process id, and the exit code of the invocation.
This function appends | ConvertTo-JSON to the command before actually invoking powershell.
An unquoted empty string is not valid JSON, but it's very normal for the Powershell output to be exactly that. Therefore, we do not attempt to parse empty Powershell output (which would result in an exception). Instead we treat this as a special case and one of two things will happen:
• If the value of the force_list parameter is True, then the result field of the return dictionary will be an empty list.
• If the value of the force_list parameter is False, then the return dictionary will not have a result key added to it. We aren't setting result to None in this case, because None is the Python representation of "null" in JSON. (We likewise can't use False for the equivalent reason.)
If Powershell's output is not an empty string and Python cannot parse its content, then a CommandExecutionError exception will be raised.
If Powershell's output is not an empty string, Python is able to parse its content, and the type of the resulting Python object is other than list then one of two things will happen:
• If the value of the force_list parameter is True, then the result field will be a singleton list with the Python object as its sole member.
• If the value of the force_list parameter is False, then the value of result will be the unmodified Python object.
If Powershell's output is not an empty string, Python is able to parse its content, and the type of the resulting Python object is list, then the value of result will be the unmodified Python object. The force_list parameter has no effect in this case.
NOTE: An example of why the force_list parameter is useful is as follows: The Powershell command dir x | Convert-ToJson results in
• no output when x is an empty directory.
• a dictionary object when x contains just one item.
• a list of dictionary objects when x contains multiple items.
By setting force_list to True we will always end up with a list of dictionary items, representing files, no matter how many files x contains.  Conversely, if force_list is False, we will end up with no result key in our return dictionary when x is an empty directory, and a dictionary object when x contains just one file.
If you want a similar function but with a raw textual result instead of a Python dictionary, you should use cmd.run_all in combination with shell=powershell.
The remaining fields in the return dictionary are described in more detail in the Returns section.
salt '*' cmd.run_all '$PSVersionTable.CLRVersion' shell=powershell salt '*' cmd.run_all 'Get-NetTCPConnection' shell=powershell
• password (str) -- Windows only. Required when specifying runas. This parameter will be ignored on non-Windows platforms.
salt myminion cmd.powershell_all 'some command' env='{"FOO": "bar"}'
• ignore_retcode -- If the exit code of the command is nonzero, this is treated as an error condition, and the output from the command will be logged to the minion log. However, there are some cases where programs use the return code for signaling and a nonzero exit code doesn't necessarily mean failure. Pass this argument as True to skip logging the output if the command has a nonzero exit code.
• depth (int) -- The number of levels of contained objects to be included.  Default is 2. Values greater than 4 seem to greatly increase the time it takes for the command to complete for some commands. eg: dir
• force_list (bool) -- The purpose of this parameter is described in the preamble of this function's documentation. Default value is False.
Returns A dictionary with the following entries:
result For a complete description of this field, please refer to this function's preamble. This key will not be added to the dictionary when force_list is False and Powershell's output is the empty string.
stderr What the PowerShell invocation wrote to stderr.
pid    The process id of the PowerShell invocation
retcode This is the exit code of the invocation of PowerShell.  If the final execution status (in PowerShell) of our command (with | ConvertTo-JSON appended) is False this should be non-0.  Likewise if PowerShell exited with $LASTEXITCODE set to some non-0 value, then retcode will end up with this value.
salt '*' cmd.powershell_all "$PSVersionTable.CLRVersion"
salt '*' cmd.powershell_all "dir mydirectory" force_list=True
salt.modules.cmdmod.retcode(cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, clean_env=False, template=None, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, password=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute a shell command and return the command's return code.
• cmd (str) -- The command to run. ex: ls -lart /home
• runas (str) --
Specify an alternate user to run the command. The default behavior is to run as the user under which Salt is running. If running on a Windows minion you must also use the password argument, and the target user account must be in the Administrators group.
WARNING: For versions 2018.3.3 and above on macosx while using runas, to pass special characters to the command you need to escape the characters on the shell.
cmd.retcode 'echo '\''h=\"baz\"'\''' runas=macuser
• group (str) -- Group to run command as. Not currently supported on Windows.
• shell (str) -- Specify an alternate shell. Defaults to the system's default shell.
salt myminion cmd.retcode 'some command' env='{"FOO": "bar"}'
Return type None
Returns Return Code as an int or None if there was an exception.
salt '*' cmd.retcode "file /bin/bash"
The template arg can be set to 'jinja' or another supported template engine to render the command arguments before execution. For example:
salt '*' cmd.retcode template=jinja "file {{grains.pythonpath[0]}}/python"
A string of standard input can be specified for the command to be run using the stdin parameter. This can be useful in cases where sensitive information must be read from standard input.
salt '*' cmd.retcode "grep f" stdin='one\ntwo\nthree\nfour\nfive\n'
salt.modules.cmdmod.run(cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, bg=False, password=None, encoded_cmd=False, raise_err=False, prepend_path=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute the passed command and return the output as a string
Specify an alternate user to run the command. The default behavior is to run as the user under which Salt is running.
WARNING: For versions 2018.3.3 and above on macosx while using runas, on linux while using run, to pass special characters to the command you need to escape the characters on the shell.
cmd.run 'echo '\''h=\"baz\"'\''' runas=macuser
• bg (bool) --
If True, run command in background and do not await or deliver its results
salt myminion cmd.run 'some command' env='{"FOO": "bar"}'
• prepend_path (str) --
$PATH segment to prepend (trailing ':' not necessary) to $PATH
• encoded_cmd (bool) --
Specify if the supplied command is encoded.  Only applies to shell 'powershell' and 'pwsh'.
Older versions of powershell seem to return raw xml data in the return.  To avoid raw xml data in the return, prepend your command with the following before encoding:
$ProgressPreference='SilentlyContinue'; <your command>
The following powershell code block will encode the Write-Output command so that it will not have the raw xml data in the return:
# target string $Command = '$ProgressPreference="SilentlyContinue"; Write-Output "hello"'
# Convert to Base64 encoded string $Encoded = [convert]::ToBase64String([System.Text.encoding]::Unicode.GetBytes($command))
Write-Output $Encoded
• raise_err (bool) -- If True and the command has a nonzero exit code, a CommandExecutionError exception will be raised.
WARNING: This function does not process commands through a shell unless the python_shell flag is set to True. This means that any shell-specific functionality such as 'echo' or the use of pipes, redirection or &&, should either be migrated to cmd.shell or have the python_shell=True flag set here.
The use of python_shell=True means that the shell will accept _any_ input including potentially malicious commands such as 'good_command;rm -rf /'.  Be absolutely certain that you have sanitized your input prior to using python_shell=True
False If True, Salt will not automatically convert the characters \\n present in the stdin value to newlines.
• windows_codepage (int) -- .INDENT 2.0
65001 Only applies to Windows: the minion uses C:WindowsSystem32chcp.com to verify or set the code page before the command cmd is executed.  Code page 65001 corresponds with UTF-8 and allows international localization of Windows.
New in version 3002.
salt '*' cmd.run "ls -l | awk '/foo/{print \\$2}'"
salt '*' cmd.run template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print \\$2}'"
Specify an alternate shell with the shell parameter:
salt '*' cmd.run "Get-ChildItem C:\\ " shell='powershell'
salt '*' cmd.run "grep f" stdin='one\\ntwo\\nthree\\nfour\\nfive\\n'
If an equal sign (=) appears in an argument to a Salt command it is interpreted as a keyword argument in the format key=val. That processing can be bypassed in order to pass an equal sign through to the remote shell command by manually specifying the kwarg:
salt '*' cmd.run cmd='sed -e s/=/:/g'
salt.modules.cmdmod.run_all(cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, redirect_stderr=False, password=None, encoded_cmd=False, prepend_path=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute the passed command and return a dict of return data
cmd.run_all 'echo '\''h=\"baz\"'\''' runas=macuser
salt myminion cmd.run_all 'some command' env='{"FOO": "bar"}'
• redirect_stderr (bool) --
If set to True, then stderr will be redirected to stdout. This is helpful for cases where obtaining both the retcode and output is desired, but it is not desired to have the output separated into both stdout and stderr.
• password --
Windows only. Required when specifying runas. This parameter will be ignored on non-Windows platforms. New in version 2016.3.0.
New in version 2016.3.6.
salt '*' cmd.run_all "ls -l | awk '/foo/{print \$2}'"
salt '*' cmd.run_all template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print \$2}'"
salt '*' cmd.run_all "grep f" stdin='one\ntwo\nthree\nfour\nfive\n'
salt.modules.cmdmod.run_bg(cmd, cwd=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, clean_env=False, template=None, umask=None, timeout=None, output_encoding=None, output_loglevel='debug', log_callback=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', password=None, prepend_path=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) New in version 2016.3.0.
Execute the passed command in the background and return its PID
NOTE: If the init system is systemd and the backgrounded task should run even if the salt-minion process is restarted, prepend systemd-run --scope to the command. This will reparent the process in its own scope separate from salt-minion, and will not be affected by restarting the minion service.
• shell (str) -- Shell to execute under. Defaults to the system default shell.
cmd.run_bg 'echo '\''h=\"baz\"'\''' runas=macuser
• shell -- Specify an alternate shell. Defaults to the system's default shell.
salt myminion cmd.run_bg 'some command' env='{"FOO": "bar"}'
WARNING: This function does not process commands through a shell unless the python_shell argument is set to True. This means that any shell-specific functionality such as 'echo' or the use of pipes, redirection or &&, should either be migrated to cmd.shell or have the python_shell=True flag set here.
The use of python_shell=True means that the shell will accept _any_ input including potentially malicious commands such as 'good_command;rm -rf /'.  Be absolutely certain that you have sanitized your input prior to using python_shell=True.
salt '*' cmd.run_bg "fstrim-all"
salt '*' cmd.run_bg template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print \\$2}'"
salt '*' cmd.run_bg "Get-ChildItem C:\\ " shell='powershell'
salt '*' cmd.run_bg cmd='ls -lR / | sed -e s/=/:/g > /tmp/dontwait'
salt.modules.cmdmod.run_chroot(root, cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=True, binds=None, env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='quiet', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, bg=False, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) New in version 2014.7.0.
This function runs cmd.run_all wrapped within a chroot, with dev and proc mounted in the chroot
• root (str) -- Path to the root of the jail to use.
• stdin (str) -- A string of standard input can be specified for the command to be run using the stdin parameter. This can be useful in cases where sensitive information must be read from standard input.:
• runas (str) -- User to run script as.
• group (str) -- Group to run script as.
• runas -- Specify an alternate user to run the command. The default behavior is to run as the user under which Salt is running. If running on a Windows minion you must also use the password argument, and the target user account must be in the Administrators group.
• binds (list) --
List of directories that will be exported inside the chroot with the bind option.
salt myminion cmd.run_chroot 'some command' env='{"FOO": "bar"}'
• clean_env (dict) -- Attempt to clean out all other shell environment variables and set only those provided in the 'env' argument to this function.
• success_retcodes -- .INDENT 2.0
Parar str stdin A string of standard input can be specified for the command to be run using the stdin parameter. This can be useful in cases where sensitive information must be read from standard input.
salt '*' cmd.run_chroot /var/lib/lxc/container_name/rootfs 'sh /tmp/bootstrap.sh'
salt.modules.cmdmod.run_stderr(cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, password=None, prepend_path=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute a command and only return the standard error
cmd.run_stderr 'echo '\''h=\"baz\"'\''' runas=macuser
salt myminion cmd.run_stderr 'some command' env='{"FOO": "bar"}'
salt '*' cmd.run_stderr "ls -l | awk '/foo/{print \$2}'"
salt '*' cmd.run_stderr template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print \$2}'"
salt '*' cmd.run_stderr "grep f" stdin='one\ntwo\nthree\nfour\nfive\n'
salt.modules.cmdmod.run_stdout(cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, password=None, prepend_path=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute a command, and only return the standard out
cmd.run_stdout 'echo '\''h=\"baz\"'\''' runas=macuser
salt myminion cmd.run_stdout 'some command' env='{"FOO": "bar"}'
salt '*' cmd.run_stdout "ls -l | awk '/foo/{print \$2}'"
salt '*' cmd.run_stdout template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print \$2}'"
salt '*' cmd.run_stdout "grep f" stdin='one\ntwo\nthree\nfour\nfive\n'
salt.modules.cmdmod.script(source, args=None, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, template=None, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, saltenv='base', use_vt=False, bg=False, password=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Download a script from a remote location and execute the script locally.  The script can be located on the salt master file server or on an HTTP/FTP server.
The script will be executed directly, so it can be written in any available programming language.
• source (str) -- The location of the script to download. If the file is located on the master in the directory named spam, and is called eggs, the source string is salt://spam/eggs
• args (str) --
String of command line args to pass to the script. Only used if no args are specified as part of the name argument. To pass a string containing spaces in YAML, you will need to doubly-quote it:
salt myminion cmd.script salt://foo.sh "arg1 'arg two' arg3"
NOTE: For Window's users, specifically Server users, it may be necessary to specify your runas user using the User Logon Name instead of the legacy logon name. Traditionally, logons would be in the following format. Domain/user
In the event this causes issues when executing scripts, use the UPN format which looks like the following. user@domain.local
More information <‐ https://github.com/saltstack/salt/issues/55080>
• group (str) -- Group to run script as. Not currently supported on Windows.
• bg (bool) -- If True, run script in background and do not await or deliver its results
salt myminion cmd.script 'some command' env='{"FOO": "bar"}'
• timeout (int) -- If the command has not terminated after timeout seconds, send the subprocess sigterm, and if sigterm is ignored, follow up with sigkill
salt '*' cmd.script salt://scripts/runme.sh salt '*' cmd.script salt://scripts/runme.sh 'arg1 arg2 "arg 3"' salt '*' cmd.script salt://scripts/windows_task.ps1 args=' -Input c:\tmp\infile.txt' shell='powershell'
salt '*' cmd.script salt://scripts/runme.sh stdin='one\ntwo\nthree\nfour\nfive\n'
salt.modules.cmdmod.script_retcode(source, args=None, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', python_shell=None, env=None, template='jinja', umask=None, timeout=None, reset_system_locale=True, saltenv='base', output_encoding=None, output_loglevel='debug', log_callback=None, use_vt=False, password=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Download a script from a remote location and execute the script locally.  The script can be located on the salt master file server or on an HTTP/FTP server.
The script can also be formatted as a template, the default is jinja.
Only evaluate the script return code and do not block for terminal output
• args (str) -- String of command line args to pass to the script. Only used if no args are specified as part of the name argument. To pass a string containing spaces in YAML, you will need to doubly-quote it: "arg1 'arg two' arg3"
salt myminion cmd.script_retcode 'some command' env='{"FOO": "bar"}'
salt '*' cmd.script_retcode salt://scripts/runme.sh salt '*' cmd.script_retcode salt://scripts/runme.sh 'arg1 arg2 "arg 3"' salt '*' cmd.script_retcode salt://scripts/windows_task.ps1 args=' -Input c:\tmp\infile.txt' shell='powershell'
salt '*' cmd.script_retcode salt://scripts/runme.sh stdin='one\ntwo\nthree\nfour\nfive\n'
salt.modules.cmdmod.shell(cmd, cwd=None, stdin=None, runas=None, group=None, shell='/bin/bash', env=None, clean_env=False, template=None, rstrip=True, umask=None, output_encoding=None, output_loglevel='debug', log_callback=None, hide_output=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, bg=False, password=None, prepend_path=None, success_retcodes=None, success_stdout=None, success_stderr=None, **kwargs) Execute the passed command and return the output as a string.
cmd.shell 'echo '\''h=\"baz\"'\''' runas=macuser
• shell (int) -- Shell to execute under. Defaults to the system default shell.
• bg (bool) -- If True, run command in background and do not await or deliver its results
salt myminion cmd.shell 'some command' env='{"FOO": "bar"}'
WARNING: This passes the cmd argument directly to the shell without any further processing! Be absolutely sure that you have properly sanitized the command passed to this function and do not use untrusted inputs.
salt '*' cmd.shell "ls -l | awk '/foo/{print \$2}'"
salt '*' cmd.shell template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print \$2}'"
salt '*' cmd.shell "Get-ChildItem C:\ " shell='powershell'
salt '*' cmd.shell "grep f" stdin='one\ntwo\nthree\nfour\nfive\n'
salt '*' cmd.shell cmd='sed -e s/=/:/g'
salt.modules.cmdmod.shell_info(shell, list_modules=False) New in version 2016.11.0.
Provides information about a shell or script languages which often use #!. The values returned are dependent on the shell or scripting languages all return the installed, path, version, version_raw
• shell (str) -- Name of the shell. Support shells/script languages include
• bash --
• cmd --
• perl --
• php --
• powershell --
• python --
• and zsh (ruby) --
• list_modules (bool) -- True to list modules available to the shell.
• only lists powershell modules. (Currently) --
Returns A dictionary of information about the shell
{'version': '<2 or 3 numeric components dot-separated>', 'version_raw': '<full version string>', 'path': '<full path to binary>', 'installed': <True, False or None>, '<attribute>': '<attribute value>'}
• installed is always returned, if None or False also returns error and may also return stdout for diagnostics.
• version is for use in determine if a shell/script language has a particular feature set, not for package management.
• The shell must be within the executable search path.
salt '*' cmd.shell_info bash salt '*' cmd.shell_info powershell
Codeauthor Damon Atkins <https://github.com/damon-atkins>
salt.modules.cmdmod.shells() Lists the valid shells on this system via the /etc/shells file
salt '*' cmd.shells
salt.modules.cmdmod.tty(device, echo='') Echo a string to a specific tty
salt '*' cmd.tty tty0 'This is a test' salt '*' cmd.tty pts3 'This is a test'
salt.modules.cmdmod.which(cmd) Returns the path of an executable available on the minion, None otherwise
salt '*' cmd.which cat
salt.modules.cmdmod.which_bin(cmds) Returns the first command found in a list of commands
salt '*' cmd.which_bin '[pip2, pip, pip-python]'
salt.modules.composer Use composer to install PHP dependencies for a directory
salt.modules.composer.did_composer_install(dir) Test to see if the vendor directory exists in this directory
dir    Directory location of the composer.json file
salt '*' composer.did_composer_install /var/www/application
salt.modules.composer.install(directory, composer=None, php=None, runas=None, prefer_source=None, prefer_dist=None, no_scripts=None, no_plugins=None, optimize=None, no_dev=None, quiet=False, composer_home='/root', env=None) Install composer dependencies for a directory.
If composer has not been installed globally making it available in the system PATH & making it executable, the composer and php parameters will need to be set to the location of the executables.
directory Directory location of the composer.json file.
composer Location of the composer.phar file. If not set composer will just execute "composer" as if it is installed globally.  (i.e. /path/to/composer.phar)
php    Location of the php executable to use with composer.  (i.e. /usr/bin/php)
runas  Which system user to run composer as.
prefer_source --prefer-source option of composer.
prefer_dist --prefer-dist option of composer.
no_scripts --no-scripts option of composer.
no_plugins --no-plugins option of composer.
optimize --optimize-autoloader option of composer. Recommended for production.
no_dev --no-dev option for composer. Recommended for production.
quiet  --quiet option for composer. Whether or not to return output from composer.
composer_home $COMPOSER_HOME environment variable
env    A list of environment variables to be set prior to execution.
salt '*' composer.install /var/www/application
salt '*' composer.install /var/www/application             no_dev=True optimize=True
salt.modules.composer.selfupdate(composer=None, php=None, runas=None, quiet=False, composer_home='/root') Update composer itself.
salt '*' composer.selfupdate
salt.modules.composer.update(directory, composer=None, php=None, runas=None, prefer_source=None, prefer_dist=None, no_scripts=None, no_plugins=None, optimize=None, no_dev=None, quiet=False, composer_home='/root', env=None) Update composer dependencies for a directory.
If composer install has not yet been run, this runs composer install instead.
salt '*' composer.update /var/www/application
salt '*' composer.update /var/www/application             no_dev=True optimize=True
salt.modules.config Return config information
salt.modules.config.backup_mode(backup='') Return the backup mode
salt '*' config.backup_mode
salt.modules.config.dot_vals(value) Pass in a configuration value that should be preceded by the module name and a dot, this will return a list of all read key/value pairs
salt '*' config.dot_vals host
salt.modules.config.gather_bootstrap_script(bootstrap=None) Download the salt-bootstrap script, and return its location
bootstrap URL of alternate bootstrap script
salt '*' config.gather_bootstrap_script
salt.modules.config.get(key, default='', delimiter=':', merge=None, omit_opts=False, omit_pillar=False, omit_master=False, omit_grains=False) New in version 0.14.0.
Attempt to retrieve the named value from the minion config file, pillar, grains or the master config. If the named value is not available, return the value specified by the default argument. If this argument is not specified, default falls back to an empty string.
Values can also be retrieved from nested dictionaries. Assume the below data structure:
{'pkg': {'apache': 'httpd'}}
To retrieve the value associated with the apache key, in the sub-dictionary corresponding to the pkg key, the following command can be used:
salt myminion config.get pkg:apache
The : (colon) is used to represent a nested dictionary level.
Changed in version 2015.5.0: The delimiter argument was added, to allow delimiters other than : to be used.
This function traverses these data stores in this order, returning the first match found:
• Minion configuration
• Master configuration (requires pillar_opts to be set to True in Minion config file in order to work)
This means that if there is a value that is going to be the same for the majority of minions, it can be configured in the Master config file, and then overridden using the grains, pillar, or Minion config file.
Adding config options to the Master or Minion configuration file is easy:
my-config-option: value cafe-menu: - egg and bacon - egg sausage and bacon - egg and spam - egg bacon and spam - egg bacon sausage and spam - spam bacon sausage and spam - spam egg spam spam bacon and spam - spam sausage spam spam bacon spam tomato and spam
NOTE: Minion configuration options built into Salt (like those defined here) will always be defined in the Minion configuration and thus cannot be overridden by grains or pillar data. However, additional (user-defined) configuration options (as in the above example) will not be in the Minion configuration by default and thus can be overridden using grains/pillar data by leaving the option out of the minion config file.
delimiter New in version 2015.5.0.
Override the delimiter used to separate nested levels of a data structure.
merge  New in version 2015.5.0.
If passed, this parameter will change the behavior of the function so that, instead of traversing each data store above in order and returning the first match, the data stores are first merged together and then searched. The pillar data is merged into the master config data, then the grains are merged, followed by the Minion config data.  The resulting data structure is then searched for a match. This allows for configurations to be more flexible.
NOTE: The merging described above does not mean that grain data will end up in the Minion's pillar data, or pillar data will end up in the master config data, etc. The data is just combined for the purposes of searching an amalgam of the different data stores.
The supported merge strategies are as follows:
• recurse - If a key exists in both dictionaries, and the new value is not a dictionary, it is replaced. Otherwise, the sub-dictionaries are merged together into a single dictionary, recursively on down, following the same criteria. For example:
>>> dict1 = {'foo': {'bar': 1, 'qux': True}, 'hosts': ['a', 'b', 'c'], 'only_x': None} >>> dict2 = {'foo': {'baz': 2, 'qux': False}, 'hosts': ['d', 'e', 'f'], 'only_y': None} >>> merged {'foo': {'bar': 1, 'baz': 2, 'qux': False}, 'hosts': ['d', 'e', 'f'], 'only_dict1': None, 'only_dict2': None}
• overwrite - If a key exists in the top level of both dictionaries, the new value completely overwrites the old. For example:
>>> dict1 = {'foo': {'bar': 1, 'qux': True}, 'hosts': ['a', 'b', 'c'], 'only_x': None} >>> dict2 = {'foo': {'baz': 2, 'qux': False}, 'hosts': ['d', 'e', 'f'], 'only_y': None} >>> merged {'foo': {'baz': 2, 'qux': False}, 'hosts': ['d', 'e', 'f'], 'only_dict1': None, 'only_dict2': None}
salt '*' config.get pkg:apache salt '*' config.get lxc.container_profile:centos merge=recurse
salt.modules.config.items() Return the complete config from the currently running minion process.  This includes defaults for values not set in the config file.
salt '*' config.items
salt.modules.config.manage_mode(mode) Return a mode value, normalized to a string
salt '*' config.manage_mode