2016-08-02 5 views
-1

요리사에서 요리법을 쓰려고하는데 리눅스에서 명령 행으로 멀티 라인을 실행할 수있는 방법을 고집합니다. 첫째로 제조법은 다음과 같습니다.요리사 멀티 라인 명령

node['freeswitch']['source']['dependencies'].each { |d| package d } 

execute "apt_update" do 
    command "wget -O - https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -&&" 
    "echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list &&" 
    "apt-get update &&" 
    "apt-get install -y --force-yes freeswitch-video-deps-most &&" 

    # because we're in a branch that will go through many rebases it's 
    # better to set this one, or you'll get CONFLICTS when pulling (update) 
    git config --global pull.rebase true 
end 

다음은 에러 출력 && 쉘의 논리 연산자 and

NoMethodError 
------------- 
No resource or method named `command' for `Chef::Recipe "source"' 

Cookbook Trace: 
--------------- 
/var/chef/cache/cookbooks/freeswitch/recipes/source.rb:6:in `from_file' 
/var/chef/cache/cookbooks/freeswitch/recipes/default.rb:5:in `from_file' 
Relevant File Content: 
---------------------- 
/var/chef/cache/cookbooks/freeswitch/recipes/source.rb: 

1: #include_recipe 'apt' 
2: 
3: node['freeswitch']['source']['dependencies'].each { |d| package d } 
4: 
5: execute "apt_update" 
6>> command 'wget -O - https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -'&& 
7: 'echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list' && 
8:   'apt-get update' && 
9:   'apt-get install -y --force-yes freeswitch-video-deps-most' && 
10: 
11: # because we're in a branch that will go through many rebases it's 
12: # better to set this one, or you'll get CONFLICTS when pulling (update) 
13:   'git config --global pull.rebase true' 
14: 
15: execute "git_clone" do 

Platform: 
--------- 
x86_64-linux 


Running handlers: 
[2016-08-02T09:19:35+01:00] ERROR: Running exception handlers 
Running handlers complete 
[2016-08-02T09:19:35+01:00] ERROR: Exception handlers complete 
Chef Client failed. 0 resources updated in 01 seconds 
[2016-08-02T09:19:35+01:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out 
[2016-08-02T09:19:35+01:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report 
[2016-08-02T09:19:35+01:00] ERROR: No resource or method named `command' for `Chef::Recipe "source"' 
[2016-08-02T09:19:35+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) 
+1

[remote_file] (https://docs.chef.io/resource_remote_file.html), [apt cookbook] (https://supermarket.chef.io/)과 같이 리소스를 Chef와 우리에게 익숙하게하십시오. cookbooks/apt) 및 [package] (https://docs.chef.io/resource_package.html) 리소스를 참조하십시오. Chef를 쉘 스크립트의 주자로 사용하지 마십시오. 너는 그것으로 재미를 느끼지 않을 것이다. – StephenKing

+0

소스에서 실행하는이 인스턴스가 기본 옵션입니다. – jaseUK

답변

0

이다. 어느 쪽이든 당신은 명시 적으로 같은 쉘에서 명령을 시작합니다

execute 'Execute a shell' do 
    command "bash -c 'cmd1 && cmd2 && ..'" 
end 

하거나 사용 bash resource :

bash 'Execute bash script' 
    code <<-EOH 
    cmd1 \ 
    && cmd2 \ 
    && ... 
    EOH 
end 
+0

그에게 이렇게 말하지 말아주세요. – StephenKing

+0

@StephenKing 제가보기에,'apt' 리소스를 사용하는 것이 더 적절할 것 같습니다. 시간을 찾으면 나는 그런 예를 준비 할 것이다. 손금으로 요리사가 없어. – hek2mgl

2

나는 질문 표시하지 않고있는 유일한 대답은 모두 아래로 투표를하지 않기 때문에 당신은 그것을하는 방법 (적어도 조금 더) 바로 여기 있습니다. 당신은 당신의 metadata.rb에 종속성으로 apt 요리 책을 선언해야

# recipes/default.rb 

# the package resource can handle multiple packages at once 
package node['freeswitch']['source']['dependencies'] 

# set up a new apt repo, import the key, automatically triggers `apt-get update` 
apt_repository "freeswitch" do 
    key "https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub" 
    uri "http://files.freeswitch.org/repo/deb/freeswitch-1.6/" 
    components ['main'] 
    distribution node['lsb']['codename'] 
end 

# finally, install this package. You could even merge the first line with this one. 
package "freeswitch-video-deps-most" 

: 귀하의 코드를 작성 원숭이는 쉽다의 repo를 추가하고 패키지를 설치하는 레시피를 만들어

# metadata.rb 
name 'whatever' 
... 

depends "apt" 

조금 익숙해지면 정말 쉽습니다. 보너스 : 그것은 멱등수입니다.