Chef-solo 无法找到 nginx 配方模板

Chef-solo 无法找到 nginx 配方模板

我最近一直在尝试使用 Chef。我想尝试使用 chef-solo 重建我的个人 Web 服务器。这是一个运行 Amazon 64 位 Linux AMI 的 AWS 实例。

我的第一个目标是安装 nginx。我已经克隆了 Opscode cookbook 存储库,并且正在使用他们的 nginx 手册

我的问题看来 chef-solo 在启动该过程后无法找到模板。

我使用的命令是

 chef-solo -j /etc/chef/dna.json

dna.json

{
  "nginx": {
    "user": "ec2-user"
  },
  "recipes": [ "nginx" ]
}

solo.rb

file_cache_path "/var/chef-solo"
cookbook_path "/var/chef-solo/cookbooks"

...输出

[root@ip-10-202-221-135 chef-solo]# chef-solo -j /etc/chef/dna.json
/usr/lib64/ruby/gems/1.9.1/gems/systemu-2.2.0/lib/systemu.rb:29: Use RbConfig instead of obsolete and deprecated Config.
[Fri, 27 Jan 2012 19:41:36 +0000] INFO: *** Chef 0.10.8 ***
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Setting the run_list to ["nginx"] from JSON
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Run List is [recipe[nginx]]
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Run List expands to [nginx]
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Starting Chef Run for ip-10-202-221-135.ec2.internal
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Running start handlers
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Start handlers complete.
[Fri, 27 Jan 2012 19:41:37 +0000] INFO: Missing gem 'mysql'
[Fri, 27 Jan 2012 19:41:38 +0000] INFO: Processing package[nginx] action install (nginx::default line 21)
[Fri, 27 Jan 2012 19:41:39 +0000] INFO: Processing directory[/var/log/nginx] action create (nginx::default line 23)
[Fri, 27 Jan 2012 19:41:39 +0000] INFO: Processing template[/usr/sbin/nxensite] action create (nginx::default line 30)
[Fri, 27 Jan 2012 19:41:39 +0000] INFO: Processing template[/usr/sbin/nxdissite] action create (nginx::default line 30)
[Fri, 27 Jan 2012 19:41:39 +0000] INFO: Processing template[nginx.conf] action create (nginx::default line 38)
[Fri, 27 Jan 2012 19:41:39 +0000] INFO: Processing template[/etc/nginx/sites-available/default] action create (nginx::default line 46)
[Fri, 27 Jan 2012 19:41:39 +0000] INFO: template[/etc/nginx/sites-available/default] mode changed to 644
[Fri, 27 Jan 2012 19:41:39 +0000] ERROR: template[/etc/nginx/sites-available/default] (nginx::default line 46) has had an error
[Fri, 27 Jan 2012 19:41:39 +0000] ERROR: template[/etc/nginx/sites-available/default] (/var/chef-solo/cookbooks/nginx/recipes/default.rb:46:in `from_file') had an error:
template[/etc/nginx/sites-available/default] (nginx::default line 46) had an error: Errno::ENOENT: No such file or directory - (/tmp/chef-rendered-template20120127-29441-1yp55vz, /etc/nginx/sites-available/default)
/usr/lib64/ruby/1.9.1/fileutils.rb:519:in `rename'
/usr/lib64/ruby/1.9.1/fileutils.rb:519:in `block in mv'
/usr/lib64/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
/usr/lib64/ruby/1.9.1/fileutils.rb:1531:in `fu_each_src_dest0'
/usr/lib64/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
/usr/lib64/ruby/1.9.1/fileutils.rb:508:in `mv'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:47:in `block in action_create'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:48:in `block in render_template'
/usr/lib64/ruby/1.9.1/tempfile.rb:316:in `open'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/mixin/template.rb:45:in `render_template'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:99:in `render_with_context'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/provider/template.rb:39:in `action_create'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource.rb:440:in `run_action'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:45:in `run_action'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block (2 levels) in converge'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `each'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:81:in `block in converge'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:94:in `block in execute_each_resource'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/resource_collection.rb:92:in `execute_each_resource'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/runner.rb:76:in `converge'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:312:in `converge'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/client.rb:160:in `run'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/solo.rb:192:in `block in run_application'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/solo.rb:183:in `loop'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application/solo.rb:183:in `run_application'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/lib/chef/application.rb:67:in `run'
/usr/lib64/ruby/gems/1.9.1/gems/chef-0.10.8/bin/chef-solo:25:in `<top (required)>'
/usr/bin/chef-solo:19:in `load'
/usr/bin/chef-solo:19:in `<main>'
[Fri, 27 Jan 2012 19:41:39 +0000] ERROR: Running exception handlers
[Fri, 27 Jan 2012 19:41:39 +0000] ERROR: Exception handlers complete
[Fri, 27 Jan 2012 19:41:39 +0000] FATAL: Stacktrace dumped to /var/chef-solo/chef-stacktrace.out
[Fri, 27 Jan 2012 19:41:39 +0000] FATAL: Errno::ENOENT: template[/etc/nginx/sites-available/default] (nginx::default line 46) had an error: Errno::ENOENT: No such file or directory - (/tmp/chef-rendered-template20120127-29441-1yp55vz, /etc/nginx/sites-available/default)

我做错了什么?

答案1

为了修复这个问题你应该将它添加到你的 nginx 默认配方的开头:

directory "/etc/nginx/sites-available" do
    owner "root"
    group "root"
    mode "0755"
end

值得一提的是,我一直在使用 Chef (Hosted)、EC2 和 Amazon Linux 做同样的事情。我花了一段时间,但我发现自己动手几乎总是更容易。我现在有十几个正在使用的配方,并且删除了最初尝试的所有 Opscode 共享配方。

事实上,我的 nginx 默认配方只有一行:

`package "nginx"`

因此,一种方法是先将其安装在您的服务器上,yum install nginx然后获取它创建的默认配置文件。将其作为模板带回您的食谱,并输入 ERB 行以根据您的需要自定义任何值。

答案2

看起来树中的目录/etc/nginx/sites-available不存在并且应该被创建。

如果您想要添加到 opscode 配方中,可以按照以下方法让 chef 为您创建目录:

http://wiki.opscode.com/display/chef/Resources#Resources-Directory

相关内容