如何在厨师中使用python解释器
作者:互联网
我想在厨师中使用python解释器.以下是我没有用的天真尝试.在python中完成下面的正确方法是什么?
script "install_something" do
interpreter "python"
user "root"
cwd "/tmp"
code <<-EOH
import boto
f = open('test.txt','r')
f.write('adfadf')
f.close()
EOH
not_if {File.exists?("/tmp/test.txt")}
end
[Mon, 02 Apr 2012 15:20:35 +0000] ERROR: Chef::Exceptions::ShellCommandFailed: script[install_something] (rtb_server::default line 101) had an error: Chef::Exceptions::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20120402-26069-3d6hob-0" ----
STDOUT:
STDERR: File "/tmp/chef-script20120402-26069-3d6hob-0", line 1
import boto
^
IndentationError: unexpected indent
---- End output of "python" "/tmp/chef-script20120402-26069-3d6hob-0" ----
Ran "python" "/tmp/chef-script20120402-26069-3d6hob-0" returned 1
解决方法:
的内容
code <<-EOH
import boto
f = open('test.txt','r')
f.write('adfadf')
f.close()
EOH
被逐字传递给口译员,也就是说包括领先的缩进词.因为缩进形成了python语法的一部分,所以你的脚本(在<< -EOH / EOH之间)是无效的python. 在这种情况下的解决方案是去除< -EOH / EOH块内的压痕.
标签:python,chef 来源: https://codeday.me/bug/20190723/1513361.html