msの日記

久しぶりに勉強したくなりプログラミングをは始めてみる。

vagrant ,chef ,git を使いcakephpを立ち上げるまでの道のり。NO3

knife-solo を使うやり方とvagrantfileのconfig.vm.provision :chef_solo do |chef|の項目を使うやりかたをごっちゃに考えていた。

以下のファイル構成で進める

Sites
├── cakephp_sample
│   ├── cookbooks
│   │   ├── group
│   │   │   ├── CHANGELOG.md
│   │   │   ├── README.md
│   │   │   ├── attributes
│   │   │   ├── definitions
│   │   │   ├── files
│   │   │   │   └── default
│   │   │   ├── libraries
│   │   │   ├── metadata.rb
│   │   │   ├── providers
│   │   │   ├── recipes
│   │   │   │   └── default.rb
│   │   │   ├── resources
│   │   │   └── templates
│   │   │       └── default
│   │   ├── httpd
│   │   │   ├── CHANGELOG.md
│   │   │   ├── README.md
│   │   │   ├── attributes
│   │   │   ├── definitions
│   │   │   ├── files
│   │   │   │   └── default
│   │   │   ├── libraries
│   │   │   ├── metadata.rb
│   │   │   ├── providers
│   │   │   ├── recipes
│   │   │   │   └── default.rb
│   │   │   ├── resources
│   │   │   └── templates
│   │   │       └── default
│   │   ├── mysql
│   │   │   ├── CHANGELOG.md
│   │   │   ├── README.md
│   │   │   ├── attributes
│   │   │   ├── definitions
│   │   │   ├── files
│   │   │   │   └── default
│   │   │   ├── libraries
│   │   │   ├── metadata.rb
│   │   │   ├── providers
│   │   │   ├── recipes
│   │   │   │   └── default.rb
│   │   │   ├── resources
│   │   │   └── templates
│   │   │       └── default
│   │   └── php
│   │       ├── CHANGELOG.md
│   │       ├── README.md
│   │       ├── attributes
│   │       ├── definitions
│   │       ├── files
│   │       │   └── default
│   │       ├── libraries
│   │       ├── metadata.rb
│   │       ├── providers
│   │       ├── recipes
│   │       │   └── default.rb
│   │       ├── resources
│   │       └── templates
│   │           └── default
│   └── vagrantfile

レシピの編集

$ vi cookbooks/httpd/recipes/default.rb
service "iptables" do
   action [:stop,:disable]
end

#php mysql-server httpd
%w{php mysql-server httpd}.each do |p|
    package p do
         action :install
    end
end

service "httpd" do
    action [:start,:enable]
end

recipeを反映する場合は vagrant provisionを実行する

$ vagrant provision

templateの設置

$ cd cookbooks/httpd/recipes/default.rbに追記

template "index.html" do
    path "/var/www/html/index.html"
    source "index.html.erb"
    mode 0644
end

$ vi cookbooks/httpd/template/default/index.html.erb

<html>Hello world</html>

vagrant provision

成功!!

cakephp導入

*1

template

設定ファイルなどの外部ファイルをChef経由で配備するためのResource

*1:http://dotinstall.com/lessons/basic_chef/24213