2012-04-02 11 views
3

シェフでPythonインタプリタを使用しようとしています。以下は私の素朴な試みがうまくいかないことです。 Pythonで以下を達成するための適切な方法は何ですか?シェフでのPythonインタプリタの使い方

code <<-EOH 
    import boto 
    f = open('test.txt','r') 
    f.write('adfadf') 
    f.close() 
    EOH 

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 

答えて

9

内容は、先頭のインデントを含むと言うことです逐語通訳、に渡されます。字下げはPython構文の一部を形成するので、あなたのスクリプト(<<-EOH/EOHの間)は有効なpythonではありません。

この場合の解決策は、<<-EOH/EOHブロック内のインデントを削除することです。

関連する問題