【发布时间】:2015-08-13 21:39:34
【问题描述】:
为简化起见,请考虑遵循食谱(食谱测试)食谱中的块。
79: bash 'Running sudo test sleep command' do
80: user 'root'
81: cwd '/tmp'
82: code <<-EOH
83: sudo sleep 1000
84: EOH
85: end
运行这个
“厨师客户-o 食谱测试”
输出:
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20150813-3835-3kj758" ----
STDOUT:
STDERR: sudo: sorry, you must have a tty to run sudo
---- End output of "bash" "/tmp/chef-script20150813-3835-3kj758" ----
Ran "bash" "/tmp/chef-script20150813-3835-3kj758" returned 1
我添加“sudo sleep”只是为了举例说明用例。在实际情况下,我们在上面的资源块中运行脚本,这些脚本有 sudo 命令。
经过一些调试发现“bash”和“execute”资源块都没有分配tty来运行它们里面的命令。
请分享你的想法。
【问题讨论】:
-
检查您的 sudoers 配置文件(通常是 /etc/sudoers)并检查
Defaults中是否有requiretty条目。如果是这样,您可以删除它,并且您的上述示例可以工作。 -
是的。检查了。是的,它确实提到了条目。但不幸的是,目前还不能删除它。
-
寻找一种不改变系统范围配置的方法。
-
bash 或执行资源是否有任何属性可以设置为在分配的 tty 中运行命令?到目前为止,我还没有在厨师文档中找到任何内容。
-
你已经在资源上设置了
user 'root',所以它将以root身份运行。为什么还需要 sudo?
标签: bash chef-infra chef-recipe cookbook