Execute the passed command and return the output as a string
Note that ``env`` represents the environment variables for the command, and
should be formatted as a dict, or a YAML string which resolves to a dict.
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
CLI Example:
salt '*' cmd.run "ls -l | awk '/foo/{print \$2}'"
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example:
salt '*' cmd.run "Get-ChildItem C:\ " shell='powershell'
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 "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'
2.5 配置管理
States 是 SaltStack中的配置语言
2.5.1 查看所有的states列表
# salt TestSlave1_Audio sys.list_state_modules | head -10
TestSlave1_Audio:
- acl
- alias
# salt TestSlave1_Audio sys.list_state_modules.apt | head -10
TestSlave1_Audio:
'sys.list_state_modules.apt' is not available.
root@Ly-banya:~# salt TestSlave1_Audio sys.state_doc file | head -10
TestSlave1_Audio:
----------
file:
Operations on regular files, special files, directories, and symlinks
=====================================================================
Salt States can aggressively manipulate files on a system. There are a number
of ways in which files can be managed.
----------
ID: /tmp/foo.conf
Function: file.managed
Result: True
Comment: File /tmp/foo.conf is in the correct state
Started: 06:26:43.545952
Duration: 7.644 ms
Changes: