Vagrantで構築したubuntu serverにchef-soloを使ってnginxを入れる
Vagrantで構築したubuntu server (ubuntu-server-12042-x64-vbox4210)にchef-soloを使ってnginxを入れたのでメモ
WEB+DB PRESSのvol.75を参考にしてみた。
recipe作成
knifeコマンドでnginxのレシピの雛形を作る。
$ sudo knife cookbook create nginx
レシピを以下のように編集。
$ sudo vi /var/chef/cookbook/nginx/recipes/default.rb package "nginx" do action :install end
chef-soloでレシピを実行。
$ sudo chef-solo -o nginx
なんかエラー出る・・。
Compiled Resource: ------------------ # Declared in /var/chef/cookbooks/nginx/recipes/default.rb:9:in `from_file' package("nginx") do action [:install] retries 0 retry_delay 2 package_name "nginx" version "1.1.19-1ubuntu0.1" cookbook_name :nginx recipe_name "default" end [2013-09-02T16:11:23+00:00] ERROR: Running exception handlers [2013-09-02T16:11:23+00:00] ERROR: Exception handlers complete Chef Client failed. 0 resources updated [2013-09-02T16:11:23+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out [2013-09-02T16:11:23+00:00] FATAL: Chef::Exceptions::Exec: package[nginx] (nginx::default line 9) had an error: Chef::Exceptions::Exec: apt-get -q -y install nginx=1.1.19-1ubuntu0.1 returned 100, expected 0
よくわからないので、apt-getを実行してみる。
$ sudo apt-get -q -y install nginx=1.1.19-1ubuntu0.1 Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: libgd2-noxpm libjpeg-turbo8 libjpeg8 libxslt1.1 nginx-common nginx-full Suggested packages: libgd-tools The following NEW packages will be installed: libgd2-noxpm libjpeg-turbo8 libjpeg8 libxslt1.1 nginx nginx-common nginx-full 0 upgraded, 7 newly installed, 0 to remove and 1 not upgraded. Need to get 403 kB/882 kB of archives. After this operation, 2,691 kB of additional disk space will be used. Err http://us.archive.ubuntu.com/ubuntu/ precise-updates/universe nginx-common all 1.1.19-1ubuntu0.1 404 Not Found [IP: 91.189.91.13 80] Err http://us.archive.ubuntu.com/ubuntu/ precise-updates/universe nginx-full amd64 1.1.19-1ubuntu0.1 404 Not Found [IP: 91.189.91.13 80] Err http://us.archive.ubuntu.com/ubuntu/ precise-updates/universe nginx all 1.1.19-1ubuntu0.1 404 Not Found [IP: 91.189.91.13 80] Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/universe/n/nginx/nginx-common_1.1.19-1ubuntu0.1_all.deb 404 Not Found [IP: 91.189.91.13 80] Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/universe/n/nginx/nginx-full_1.1.19-1ubuntu0.1_amd64.deb 404 Not Found [IP: 91.189.91.13 80] Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/universe/n/nginx/nginx_1.1.19-1ubuntu0.1_all.deb 404 Not Found [IP: 91.189.91.13 80] E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
apt-getが古い?せいか404が出てるのが原因のようだ。apt-getをupdateしてみる。
$ apt-get update
もう一度レシピを実行。
$ sudo chef-solo -o nginx Compiling Cookbooks... Converging 1 resources Recipe: nginx::default * package[nginx] action install - install version 1.1.19-1ubuntu0.2 of package nginx Chef Client finished, 1 resources updated
入った!一応バージョンを確認。
$ nginx -v nginx version: nginx/1.1.19
大丈夫そう。