当我运行带有管道或重定向的任何命令时,它会失败。
master和minion都在Digital Ocean的新Ubuntu 14.04盒子上运行,以测试Salt。
两者都是使用引导脚本从git中提取最新分支来安装的。
这是我得到的:
# salt-call --local cmd.run "ps aux | grep hello" -l debug
[DEBUG ] Reading configuration from /etc/salt/minion
[DEBUG ] Using cached minion ID from /etc/salt/minion_id: XXX.XXX.XX
[DEBUG ] Configuration file path: /etc/salt/minion
[DEBUG ] Reading configuration from /etc/salt/minion
[DEBUG ] Failed to import module debian_service. The exeception was No module named systemd. Another attempt will be made to try to resolve dependencies.
[DEBUG ] compile template:
[ERROR ] Template does not exist:
[INFO ] Executing command 'ps aux | grep hello' in directory '/root'
[ERROR ] Command 'ps aux | grep hello' failed with return code: 1
[ERROR ] output: error: garbage option
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
没有管道它工作正常,但显然会返回完整的输出。
答案 0 :(得分:6)
尝试使用python_shell=True
或cmd.shell
:
root@323be0968814:/# salt-call --local cmd.run "ps aux | grep hello" python_shell=True
[INFO ] Executing command 'ps aux | grep hello' in directory '/root'
local:
root 4796 0.0 0.1 134688 24200 ? S+ 14:50 0:00 /usr/bin/python /usr/bin/salt-call --local cmd.run ps aux | grep hello python_shell=True
root 4819 0.0 0.0 4444 652 ? S+ 14:50 0:00 /bin/sh -c ps aux | grep hello
root 4821 0.0 0.0 4444 104 ? R+ 14:50 0:00 /bin/sh -c ps aux | grep hello
root@323be0968814:/# salt-call --local cmd.shell "ps aux | grep hello"
[INFO ] Executing command 'ps aux | grep hello' in directory '/root'
local:
root 4822 0.0 0.1 134688 24204 ? S+ 14:52 0:00 /usr/bin/python /usr/bin/salt-call --local cmd.shell ps aux | grep hello
root 4845 0.0 0.0 4444 648 ? S+ 14:52 0:00 /bin/sh -c ps aux | grep hello
root 4847 0.0 0.0 4444 100 ? R+ 14:52 0:00 /bin/sh -c ps aux | grep hello
来自the cmd.run
docs(强调我的):
警告:此函数不通过shell处理命令 除非python_shell标志设置为True。 这意味着任何 特定于shell的功能,例如'echo'或使用管道, 重定向或&amp;&amp;,应该迁移到cmd.shell或具有 python_shell =此处设置了真正的标志。