chefでnginxをインストールする方法
Mac OS XでVagrantとChefを使った環境構築のまとめ
http://qiita.com/hamichamp/items/e27a0ecacc33482936c8
上記サイトを参考にchefを触ってたら、以下のコマンドでエラーが出た。
knife solo cook centos
Compiling Cookbooks...
================================================================================
Recipe Compile Error
================================================================================
Chef::Exceptions::RecipeNotFound
--------------------------------
could not find recipe epel for cookbook yum
Running handlers:
[2015-07-06T12:51:05+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-07-06T12:51:05+00:00] ERROR: Exception handlers complete
[2015-07-06T12:51:05+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.506660684 seconds
[2015-07-06T12:51:05+00:00] ERROR: could not find recipe epel for cookbook yum
[2015-07-06T12:51:05+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ERROR: RuntimeError: chef-solo failed. See output above.
epelが見つからないらしい。
ノードの設定を以下のように変更。
nodes/centos.json
"run_list": [
"yum",
"nginx"
],
リトライ。
knife solo cook centos
Recipe: nginx::package
* yum_package[nginx] action install
================================================================================
Error executing action `install` on resource 'yum_package[nginx]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /usr/bin/python /opt/chef/embedded/apps/chef/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 ----
STDOUT: [option installonlypkgs] kernel kernel-bigmem installonlypkg(kernel-module) installonlypkg(vm) kernel-enterprise kernel-smp kernel-debug kernel-unsupported kernel-source kernel-devel kernel-PAE kernel-PAE-debug
STDERR: yum-dump Repository Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
---- End output of /usr/bin/python /opt/chef/embedded/apps/chef/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 ----
Ran /usr/bin/python /opt/chef/embedded/apps/chef/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 returned 1
Resource Declaration:
---------------------
# In /home/vagrant/chef-solo/cookbooks-2/nginx/recipes/package.rb
41: package node['nginx']['package_name'] do
42: options package_install_opts
43: notifies :reload, 'ohai[reload_nginx]', :immediately
44: not_if 'which nginx'
45: end
46:
Compiled Resource:
------------------
# Declared in /home/vagrant/chef-solo/cookbooks-2/nginx/recipes/package.rb:41:in `from_file'
yum_package("nginx") do
action :install
retries 0
retry_delay 2
default_guard_interpreter :default
package_name "nginx"
timeout 900
flush_cache {:before=>false, :after=>false}
declared_type :package
cookbook_name :nginx
recipe_name "package"
not_if "which nginx"
end
Running handlers:
[2015-07-06T12:53:07+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-07-06T12:53:07+00:00] ERROR: Exception handlers complete
[2015-07-06T12:53:07+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 1 resources updated in 3.810216806 seconds
[2015-07-06T12:53:07+00:00] ERROR: yum_package[nginx] (nginx::package line 41) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /usr/bin/python /opt/chef/embedded/apps/chef/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 ----
STDOUT: [option installonlypkgs] kernel kernel-bigmem installonlypkg(kernel-module) installonlypkg(vm) kernel-enterprise kernel-smp kernel-debug kernel-unsupported kernel-source kernel-devel kernel-PAE kernel-PAE-debug
STDERR: yum-dump Repository Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
---- End output of /usr/bin/python /opt/chef/embedded/apps/chef/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 ----
Ran /usr/bin/python /opt/chef/embedded/apps/chef/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 returned 1
[2015-07-06T12:53:07+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ERROR: RuntimeError: chef-solo failed. See output above.
調べたところ以下の手順でインストール可能らしい。
cookbook v3.0からの変更みたい。
knife cookbook create nginx -o site-cookbooks/
vim site-cookbooks/nginx/recipes/default.rb
defaul.rb
# add the EPEL repo
yum_repository 'epel' do
description 'Extra Packages for Enterprise Linux'
mirrorlist 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch'
fastestmirror_enabled true
gpgkey 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'
action :create
end
package "nginx" do
action [:install]
end
knife solo cook centos
エラーがなくなり成功。
以下のコマンドでインストールされていることを確認。
ssh centos
nginx -v
参考サイト
ChefでEPELをインストールできない
http://qiita.com/kenji0x02/items/3c815833ff188646effe
はじめてのChef
http://www.sharkpp.net/blog/2014/04/18/first-step-chef.html