【发布时间】:2016-06-30 17:02:09
【问题描述】:
我正在尝试创建一个 salt 执行模块,但在模块中正确使用 cmd.run 时遇到问题。
如果我跑步(使用无主仆从):
salt-call cmd.run "cat hey.txt | grep 'hey there'"
我明白了:
[INFO ] Executing command 'cat hey.txt | grep 'hey there'' in directory '/root'
local:
hey there
这是我所期望的,因为它在文件上使用 cat 并 greps 相应的行。但是,当我在执行模块中将其作为函数实现时:
def foo():
return __salt__['cmd.run']("cat hey.txt | grep 'hey there'")
我在同步模块后调用它:
salt-call example.foo
它返回(第二个错误只是打印 hey.txt 的内容):
[INFO ] Executing command 'cat hey.txt | grep 'hey there'' in directory '/root'
[ERROR ] Command 'cat hey.txt | grep 'hey there'' failed with return code: 1
[ERROR ] output: hey there
stranger
I like your
boots
cat: '|': No such file or directory
cat: grep: No such file or directory
cat: 'hey there': No such file or directory
local:
hey there
stranger
I like your
boots
cat: '|': No such file or directory
cat: grep: No such file or directory
cat: 'hey there': No such file or directory
所以似乎由于某种原因它没有将 grep 识别为命令,只是试图在命令行上对所有内容进行分类,但 INFO 说该命令的运行与我直接执行的完全相同通过调用 cmd.run,所以我很困惑为什么会这样。
【问题讨论】:
-
您可以回答自己的问题并接受它以帮助可能遇到与您相同问题的其他人:)
标签: python grep salt-stack