linux - Chef 多行命令

标签 linux chef-infra

我正在尝试在 Chef 中编写一个菜谱,但我一直不知道如何在 Linux 中的命令行中执行多行执行。首先是配方,接下来是我收到的错误输出。

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

下面是错误输出

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)

最佳答案

&& 是 shell 的逻辑 and 运算符。您可以在 shell 中显式启动该命令,例如:

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

或者您使用bash resource :

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

关于linux - Chef 多行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38715354/

相关文章:

chef-infra - 如何识别 Chef Recipe 修改/触及的文件

java - 得到 "undefined method ` [ ]' for nil:NilClass"安装 java Cookbook

json - 在Chef中使用属性

linux - 任何人都有想法,这是什么编辑器?

linux - 在 jenkins gerrit 触发器中添加 ssh key 文件 : "/...../.ssh/id_rsa" does not exist

chef-infra - Chef Windows - 要求 block 失败

chef-infra - Chef 长的坚持

c++ - 将 .bin 输入文件复制到 Linux 中

java - 在非root用户下启动tomcat 9

linux - 在挂载文件系统之前在C++代码程序中运行 "fsck"命令好吗?