如何通过Chef更新Nginx [英] How to update nginx via Chef

查看:86
本文介绍了如何通过Chef更新Nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,这是我在 ServerFault 上询问的问题的副本,但无法获得答案.希望我能在这里得到一些反馈.

Note this is a copy of a question I asked on ServerFault but was unable to get an answer for. Hoping I can get some feedback here.

我是一名开发人员,最近继承了我们以前的devops人员的厨师设置.我正在运行Chef 10服务器,并且已经意识到opscode中的nginx食谱仍然使用nginx版本1.2.6.由于已经发布了许多安全补丁,因此我想转到1.4.1,并认为Chef应该非常容易做到这一点.但是事实证明这是一场噩梦.

I am a developer who recently inherited our previous devops person's chef setup. I'm running Chef 10 server and have realized that the nginx cookbook from opscode still uses nginx version 1.2.6. Since there are many security patches that have been released I'd like to move to 1.4.1 and feel that Chef should make this very easy. However it has proven to be nightmarish.

我的第一个想法是简单地将nginx菜谱设为自定义",并将default['nginx']['version']属性更改为1.4.1,上传菜谱并聚合测试服务器.我看到它获取了食谱的新版本(我记得要更新元数据),并在继续使用1.2.6时迅速忽略它.

My first thought was to simply make the nginx cookbook "custom" and change the default['nginx']['version'] attribute to 1.4.1, upload the cookbook and converge a testing server. I watched it fetch the new version of the cookbook (I remembered to update the metadata), and promptly ignore it as it continued using 1.2.6.

然后,我认为我应该覆盖我正在使用的角色中的属性(rails_tier_web是该角色的名称).他与经验丰富的厨师长交谈时告诫不要这样做,因为无法对角色进行版本控制,并且无法像菜谱那样固定角色.但是,在阅读该食谱的文档时,他们告诉您在您的角色中使用替代属性,这就是我所做的事情:

Then I thought I should override attributes in the role I am using (rails_tier_web is the name of the role). Speaking with a more experienced Chef person he cautioned against it since roles cannot be versioned and pinned the way cookbooks can. However reading the documentation for the cookbook, they tell you to use the override attributes in your role so that's what I've done:

override_attributes( 'nginx' => { 'source' => { 'version' => '1.4.1', 'prefix' => '/opt/nginx-1.4.1' }, 'version' => '1.4.1' } )

override_attributes( 'nginx' => { 'source' => { 'version' => '1.4.1', 'prefix' => '/opt/nginx-1.4.1' }, 'version' => '1.4.1' } )

但是,当我收敛时,仍然在日志输出中看到1.2.6的痕迹.

However when I converge I am still seeing traces of 1.2.6 show up in the log output.

[2013-07-15T18:52:03-04:00] INFO: Processing remote_file[http://nginx.org/download/nginx-1.2.6.tar.gz] action create (nginx::source line 56)
[2013-07-15T18:52:05-04:00] INFO: remote_file[http://nginx.org/download/nginx-1.2.6.tar.gz] updated

然后在那之后...

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20130715-4790-1m689ee" ----
STDOUT:
STDERR: /tmp/chef-script20130715-4790-1m689ee: line 2: cd: nginx-1.4.1: No such file or directory
---- End output of "bash"  "/tmp/chef-script20130715-4790-1m689ee" ----
Ran "bash"  "/tmp/chef-script20130715-4790-1m689ee" returned 1

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/nginx/recipes/source.rb

 84: bash "compile_nginx_source" do
 85:   cwd ::File.dirname(src_filepath)
 86:   code <<-EOH
 87:     tar zxf #{::File.basename(src_filepath)} -C #{::File.dirname(src_filepath)} &&
 88:     cd nginx-#{node['nginx']['source']['version']} &&
 89:     ./configure #{node.run_state['nginx_configure_flags'].join(" ")} &&
 90:     make && make install
 91:   EOH
 92:
 93:   not_if do
 94:     nginx_force_recompile == false &&
 95:       node.automatic_attrs['nginx'] &&
 96:       node.automatic_attrs['nginx']['version'] == node['nginx']['source']['version'] &&
 97:       node.automatic_attrs['nginx']['configure_arguments'].sort == configure_flags.sort
 98:   end
 99:
100:   notifies :restart, "service[nginx]"
101: end
102:

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/nginx/recipes/source.rb:84:in `from_file'

bash("compile_nginx_source") do
  action "run"
  retries 0
  retry_delay 2
  command "\"bash\"  \"/tmp/chef-script20130715-4790-1m689ee\""
  backup 5
  cwd "/var/chef/cache"
  returns 0
  code "    tar zxf nginx-1.4.1.tar.gz -C /var/chef/cache &&\n    cd nginx-1.4.1 &&\n    ./configure --prefix=/opt/nginx-1.2.6 --conf-path=/etc/nginx/nginx.conf --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module &&\n    make && make install\n"
  interpreter "bash"
  cookbook_name "nginx"
  recipe_name "source"
  not_if { #code block }
end

我真是机智,因为我希望我可以重写版本属性并将其全部放置到位.显然,到目前为止,情况并非如此,如果可以的话,我真的不希望手动修补和/或编辑节点对象.任何帮助将不胜感激.

I am really at wits end because I was hoping I could just override a version attribute and have it all fall into place. Obviously that is not the case thus far and I really don't want to have to do manual patching and/or editing of node objects if I can help it. Any help would be appreciated.

推荐答案

我遇到了同样的问题.据我所知,问题的根源是在Nginx食谱的属性文件中使用了字符串连接.如果您查看attribute/source.rb,则会看到以下内容

I'm running into this very same issue. Best I can tell, the root of the issue is the use of string concatenation in the attributes files in the nginx cookbook. If you look at attributes/source.rb you see the following

default['nginx']['source']['default_configure_flags'] = [
  "--prefix=#{node['nginx']['source']['prefix']}",
  "--conf-path=#{node['nginx']['dir']}/nginx.conf",
  "--sbin-path=#{node['nginx']['source']['sbin_path']}"
]

这些是很好的,合理的默认值.有人会认为,如果一个人覆盖了引用的属性之一node ['nginx'] ['source'] ['prefix'],那么生成的default_configure_flags将反映这一变化.但是,事实并非如此.看起来,属性文件是运行Chef时首先加载的东西之一(如果不是).因此,分配给诸如default_configure_flags之类的值的是基于食谱提供的默认值(即,在attribute/default.rb中设置的版本字符串1.2.6).

These are fine, reasonable defaults. And one would think that if one overrides one of the referenced attributes, node['nginx']['source']['prefix'], then the resulting default_configure_flags would reflect that change. However, that doesn't appear to be the case. It looks like attributes files are one of, if not the, first things loaded when running chef. So the values assigned to things like default_configure_flags are based on the defaults provided with the cookbook (i.e. the version string 1.2.6 which is set in attributes/default.rb).

对Nginx食谱本身进行一些认真的清理工作很短,我最好的解决方案是覆盖我自己的属性文件中的default_configure_flags属性(以及其他一些看起来还不错的属性,但会导致同样的问题) ,请查看其余的attribute/source.rb进行重置).不幸的是,我将其覆盖为默认值,只是稍后将其引用的其他值设置为我想要的值之后对其进行评估.

Short of doing some serious cleanup work on the nginx cookbook itself, my best solution was to override the default_configure_flags attribute in my own attributes file (along with a number of others that seem like they should be fine, but cause the same issue, look at the rest of the attributes/source.rb for the reset). Unfortunately, I'm overriding it to the same thing as the default, it just get's evaluated later after the other values that it references are set to what I want.

这篇关于如何通过Chef更新Nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆