CentOSにapacheインストールとiptables停止をchefで行います。
そのためのchefクックブックを作成する手順です。
chefクックブック(レポジトリ)作成
knife solo initでひな形となるディレクトリとファイルが生成できます。
今回はchef-repoというクックブック名で作成します。
knife solo init chef-repo
chef-repoディレクトリの中身。
$ cd chef-repo
$ ls
Cheffile
data_bags
roles
cookbooks
nodes
site-cookbooks
クックブックをgitで管理します。
$ git init
$ git add .
$ git commit -m "first commit"
apacheのレシピ作成
httpdパッケージをyumでインストールするレシピを作成します。
$ knife cookbook create httpd -o site-cookbooks
$ vi site-cookbooks/httpd/recipes/default.rb
site-cookbooks/httpd/recipes/default.rb
package "httpd" do
action :install
end
service "httpd" do
supports :status => true, :restart => true, :reload => true
action [ :enable , :start ]
end
iptablesのレシピ作成
iptablesはhttpの80ポートを開放すればいいのですが、iptablesの設定を変更するのが面倒なのでiptables自体を停止させます。
本番環境で推奨できる方法ではありません。
$ knife cookbook create iptables_stop -o site-cookbooks
$ vi site-cookbooks/iptables_stop/recipes/default.rb
site-cookbooks/iptables_stop/recipes/default.rb
service "iptables" do
supports :status => true, :restart => true, :reload => true, :stop => true
action [ :disable , :stop ]
end
nodesディレクトリに192.168.33.10.jsonファイルを作成します。
VagrantのCentOSのIPアドレスは「192.168.33.10」に設定している場合です。
nodes/192.168.33.10.json
{
"run_list":[
"iptables_stop",
"httpd"
]
}
クックブックができあがりました。
本クックブックはgithubに公開しています。
https://github.com/pakiln/chef-repo