我正在写一个厨师食谱来安装nginx和Phusion Passenger等。 简短的总结是,我的运行列表上的食谱没有按照我预期的顺序执行,这导致apt套件安装失败,我不知道如何解决。 整个序列有点复杂,我会尽我所能保持基本的细节。
我有我自己的配方, lr-web用于定制Web服务器到我想要的状态。其中一个动作是对nginx.conf进行更改。 我还有一个angular色来编排总体configuration,其运行列表是:
"run_list":[ "recipe[apt]", "recipe[nginx]", "recipe[passenger]", "recipe[lr-web]" ]
而且, lr-web配方在其metadata.rb列出了passenger和nginx作为依赖关系。
apt和nginx食谱是标准的OpsCode。 但是我写了自己的passenger配方,因为OpsCode使用rubygems来安装乘客,但是这个版本不再支持。 遵循modrails.com的build议,通过apt来安装,我的passenger食谱中有以下步骤:
cookbook_file "/etc/apt/sources.list.d/passenger.list" do source "passenger.list" mode 600 action :create_if_missing end bash "apt-get-update" do user "root" code <<-EOF apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 apt-get install apt-transport-https ca-certificates apt-get update EOF end apt_package "nginx-extras" do action :install end
当我收敛节点时会发生什么,即使它传递了-y标志,我得到了来自apt-get的提示,因为nginx-extras软件包安装程序不想覆盖nginx.conf :
Configuration file `/etc/nginx/nginx.conf' ==> Modified (by you or by a script) since installation. ==> Package distributor has shipped an updated version. What would you like to do about it ? Your options are: Y or I : install the package maintainer's version N or O : keep your currently-installed version D : show the differences between the versions Z : start a shell to examine the situation The default action is to keep your current version. *** nginx.conf (Y/I/N/O/D/Z) [default=N] ? Configuration file `/etc/nginx/sites-available/default' ==> Modified (by you or by a script) since installation. ==> Package distributor has shipped an updated version. What would you like to do about it ? Your options are: Y or I : install the package maintainer's version N or O : keep your currently-installed version D : show the differences between the versions Z : start a shell to examine the situation The default action is to keep your current version. *** default (Y/I/N/O/D/Z) [default=N] ? dpkg: error processing nginx-common (--configure): EOF on stdin at conffile prompt dpkg: dependency problems prevent configuration of nginx-extras: nginx-extras depends on nginx-common (= 1:1.4.4-2.4.0.37~precise1); however: Package nginx-common is not configured yet. dpkg: error processing nginx-extras (--configure): dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup error from a previous failure. Errors were encountered while processing: nginx-common nginx-extras E: Sub-process /usr/bin/dpkg returned an error code (1)
据我所知,唯一的办法就是如果我的lr-web食谱在旅客配方之前运行,这是不应该的。
所以。 我的问题是, lr-web在passenger之前运行,因此改变了nginx conf。 我需要找出为什么发生这种情况,并停止它,或者当apt_package安装nginx-extras来传递“N”响应,说“不要覆盖nginx.conf”时,find一种方法。 任何angular度的任何build议将是非常受欢迎的。
这可能是由于nginx cookbook在被apt安装后修改了/etc/nginx/nginx.conf文件,dpkg命令会警告您有关该更改。 这也会在/etc/nginx/sites-available/default发生冲突。
将旅客配方放在nginx之上将确保安装repo和packages。 由于nginx-extras提供了它自己的nginx.conf文件,这个文件会立即被nginx配方覆盖,并从那里被控制。
你修改后的运行列表如下所示:
"run_list":[ "recipe[apt]", "recipe[passenger]", "recipe[nginx]", "recipe[lr-web]" ]
你也可以尝试用自己想要的方式做出反应 – 这有可能会对apt的行为有点过于激进,可能会影响Chef运行的其他部分。 我不build议这样做,但是你可以试试看看它是否适合你的用例。
ENV['DEBIAN_FRONTEND'] = 'noninteractive' package 'nginx-extras' do options '--force-yes' options '-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"' action :install end
在这里阅读更多。
这样就有这样的危险,就是为其他资源回答这个问题,而不是将问题提交给操作员,以及让资源相互覆盖,触发不需要的通知给其他资源,比如在configuration文件发生变化时触发nginx重启,等等
这并不是真正解决sorting问题,只是更好的厨师资源使用。
你显示提供一个食谱文件,然后执行bash资源来激活它们。 如果没有用only_if / not_if语句保护,每次运行都会发生这种情况。
您正在使用的apt cookbook 已经有一个存储库资源 ,并且会将您的配方更改为如下所示:
apt_repository 'passenger' do uri 'https://oss-binaries.phusionpassenger.com/apt/passenger' distribution node['lsb']['codename'] components ['main'] keyserver 'keyserver.ubuntu.com' key '561F9B9CAC40B2F7' end
然后,这将在运行期间以更安全的方式运行apt-get命令,输出结果几乎相同:
deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main
(在Ubuntu 12.04上)
使用第一个解决scheme来更改配方对两个不同包提供的文件所做的更改的顺序。
使用第三个解决scheme进一步清理代码。