简体   繁体   English

厨师食谱编译错误

[英]Chef Recipe Compile Error

Does anyone know why the following code results the error: undefined method 'tar' for "riak-1.4.2":String 有谁知道为什么以下代码会导致错误: “ riak-1.4.2”的未定义方法'tar':String

remote_file "/vagrant/usr/src/#{node.default['riak']['version'].tar.gz}" do
  source "#{node.default['riak']['url']}"
  mode 0755
  notifies :run, "bash[extract_riak]", :immediately
end

bash "extract_riak" do 
  code <<-EOH
    # Following is the line which causes the error.
    /bin/tar xzf /vagrant/usr/src/#{node.default['riak']['version']}.tar.gz -C /vagrant/usr/src/#{node.default['riak']['version']}
  EOH
  notifies :run, "bash[make_riak]", :immediately
end

This line is raising the error: 这行引发错误:

remote_file "/vagrant/usr/src/#{node.default['riak']['version'].tar.gz}"

The .tar.gz should be outside the brackets, like so: .tar.gz应该在方括号之外,如下所示:

remote_file "/vagrant/usr/src/#{node.default['riak']['version']}.tar.gz"

Everything between the brackets is executed as ruby code and the result takes it's place in the string. 括号之间的所有内容都作为ruby代码执行,并且结果将其放置在字符串中。 node.default['riak']['version'].tar.gz is a chain of function calls, including calling a non-existent tar and gz function at the end. node.default['riak']['version'].tar.gz是函数调用链,包括最后调用不存在的targz函数。 These are part of the filename, and should go outside the brackets. 这些是文件名的一部分,应放在方括号之外。

As a side note, you probably want to use node[:attribute] to get attributes, and only use node.default[:attribute] to set attributes. 附带说明一下,您可能希望使用node[:attribute]获取属性,而仅使用node.default[:attribute]设置属性。

I recommend the ark cookbook as better choice for handling archives. 我推荐方舟食谱作为处理档案的更好选择。

The following example recipe: 以下示例配方:

include_recipe "ark"

ark "riak" do
  url "http://s3.amazonaws.com/downloads.basho.com/riak/1.4/1.4.2/riak-1.4.2.tar.gz"
  version "1.4.2"
end

will install riak under the "/usr/local/riak-1.4.2" directory. 将在“ /usr/local/riak-1.4.2”目录下安装riak。

Finally, there is a riak cookbook available as well, which reportedly will also install from source. 最后,还有一本riak食谱 ,据报道也可以从源代码中安装。

Instead of: 代替:

#{node.default['riak']['version']}.tar.gz

you want: 你要:

#{node.default['riak']['version'].tar.gz}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM