わすれっぽいきみえ

みらいのじぶんにやさしくしてやる

サードパーティ製chefレシピ使ってたの忘れてた

vagrantErlangを入れたし、さぁてRabbitMQ使っちゃうぞー、PHPで触っちゃうぞーと思ってたら

$ php -v
-bash: php: command not found

マジかよ。
chefのレシピ流し込むのを忘れてたわ。

> knife solo cook vagrant
Running Chef on vagrant...
Checking Chef version...
Uploading the kitchen...
Generating solo config...
Running Chef...
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
[2014-01-13T16:51:04+09:00] ERROR: Running exception handlers
[2014-01-13T16:51:04+09:00] ERROR: Exception handlers complete
[2014-01-13T16:51:04+09:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2014-01-13T07:51:04+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ERROR: RuntimeError: chef-solo failed. See output above.

えー、今日エラー起こしすぎでしょう…。

で、ググってみたところまったく同じことで1週間前にハマった人の記事を見つけた。
ChefにおけるChildConvergeErrorへの対処法 - 酒飲みの備忘録

この人のいうようにやってみたら今度は次のようなエラーを吐いた。

[2014-01-13T17:25:10+09:00] DEBUG: Chef::Exceptions::RecipeNotFound: could not find recipe epel for cookbook yum

ん?epelがない??

困ってChef Cookbook: yum - Opscode Communityを見に行ったら、以前のようなjsonの書き方ではepelがもう使えないらしい。

before

{
    "tz": "Asia/Tokyo",
    "run_list":[
        "timezone-ii",
        "yum::epel",
        "yum::remi",
        "recipe[hello]"
    ]
}

after

{
    "tz": "Asia/Tokyo",
    "run_list":[
        "timezone-ii::rhel",
        "yum",
        "recipe[hello]"
    ]
}

afterの表記にした後

> knife solo cook vagrant
なんかいろいろ
[2014-01-13T17:17:51+09:00] INFO: Chef Run complete in 308.453288587 seconds
[2014-01-13T17:17:51+09:00] INFO: Running report handlers
[2014-01-13T17:17:51+09:00] INFO: Report handlers complete
Chef Client finished, 19 resources updated[0m
[2014-01-13T17:17:51+09:00] DEBUG: Forked child successfully reaped (pid: 6860)
[2014-01-13T17:17:51+09:00] DEBUG: Exiting
Run finished in 315.618079 seconds

今度はうまくいった。
しかしリモートでphpのバージョンを確認してみたら

$ php -v
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

ですよね、だってepel指定してないもん。

というわけで、helloレシピのdefault.rbを編集。*1

# 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

# add the Remi repo
yum_repository 'remi' do
  description 'Les RPM de Remi - Repository'
  baseurl 'http://rpms.famillecollet.com/enterprise/6/remi/x86_64/'
  gpgkey 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi'
  fastestmirror_enabled true
  action :create
end

%w{mysql-server php php-pear php-mbstring php-xml php-devel php-mysql php-gd}.each do |pkg|
    package pkg do
        options "--enablerepo=remi"
        action :install
    end
end

これでリポジトリが追加できたので、それに応じてphpmysqlを入れる。*2
ローカル

> knife solo cook vagrant
(なんかいろいろ)
Chef Client finished, 12 resources updated

リモートでphpのバージョン確認

$ php -v
PHP 5.4.24 (cli) (built: Jan  9 2014 07:32:12)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

できた。

しかしやっぱり何がどんな風に入ってるかの保証のためにserverspec入れたいな…。今日はここまでにするけども。

*1:helloレシピは私個人でテスト用に作ったcookbookで、よく「chefでhello worldと表示させてみましょう」って入門で見るようなやつをそのままの名前で使ってるだけ。

*2:実際の作業ではhttp://rpms.famillecollet.com/enterprise/6/remi/x86_64/を探し当てるのに苦労した。https://github.com/opscode-cookbooks/yumにはepelの追加方法は載っているがremiは載っていない。それでどうやってremiのcentos用をインストールしようかと思って、ずっとindexツリーを探してて、http://rpms.famillecollet.com/enterprise/6/remi/x86_64/repoview/までリンクをクリックしてなんとなくrepoviewをurlから消してみたらいけた。