Linux Chef多行命令
我试图在Chef中编写一个菜谱,但我一直在研究如何在Linux中将多行执行转换为命令行。首先是配方,然后是我收到的错误输出Linux Chef多行命令,linux,chef-infra,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 | a
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
或者您使用:
因为我不想在不告诉你们怎么做的情况下否决这两个问题和唯一的答案,至少再正确一点,给你们。您的代码编写猴子创建了一个配方,用于添加apt repo并安装程序包: recipes/default.rb 包资源可以一次处理多个包 包节点['freeswitch']['source']['dependencies'] 设置新的apt回购,导入密钥,自动触发“apt get update”` apt_可自由切换吗 钥匙https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub urihttp://files.freeswitch.org/repo/deb/freeswitch-1.6/ 组件['main'] 分发节点['lsb']['codename'] 终止 最后,安装这个软件包。您甚至可以将第一行与这一行合并。 软件包自由切换视频deps most 您只需在元数据中将cookbook声明为依赖项。rb: 元数据.rb 叫“随便什么” ... 视情况而定
这真的很容易,只要你习惯了。奖励:它是幂等的。在这种情况下,从源代码运行是首选选项。@StephenKing我明白了,在这里使用apt资源似乎更合适。当我有时间的时候,我会准备这样一个例子。不要让厨师在自动取款机旁。
bash 'Execute bash script'
code <<-EOH
cmd1 \
&& cmd2 \
&& ...
EOH
end