2012-04-02 5 views
3

요리사에서 파이썬 인터프리터를 사용하려고합니다. 아래는 작동하지 않은 나의 순진한 시도입니다. 아래에서 파이썬으로 수행하는 적절한 방법은 무엇입니까?요리사에서 파이썬 인터프리터를 사용하는 방법

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

내용은 주요 들여 쓰기를 포함하여 말을하는 것입니다 그대로 인터프리터에 전달됩니다. 들여 쓰기는 파이썬 구문의 일부이므로 양식 (<<-EOH/EOH 사이)은 유효한 파이썬이 아닙니다.

이 경우 솔루션은 <<-EOH/EOH 블록 내의 들여 쓰기를 제거하는 것입니다.

관련 문제