ChefSoloの使い方
ChefServerは3台必要でしたが、ChefSoloは1台でChefを実行できます。
今回はChefSoloを使ってWebサーバを構築します。
サーバの準備
vagrantを使っています。
Vagrant file
$ vim Vagrantfile VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.define :centos2 do |dev| dev.vm.box = "chef/centos-6.5" dev.vm.hostname = "dev102" dev.vm.network :private_network, ip: "10.0.0.102" end end |
構築
$ vagrant up centos2 |
ログイン
$ vagrant ssh centos2 |
ChefSoloをインストール
$ wget https://www.opscode.com/chef/install.sh $ sudo bash install.sh -v 11.4.0 |
レシピの作成
knifeの初期化
$ knife configure
WARNING: No knife configuration file found
Where should I put the config file? [/home/vagrant/.chef/knife.rb]
Please enter the chef server URL: http://dev102:4000
Please enter an existing username or clientname for the API: [vagrant]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef/validation.pem]
Please enter the path to a chef repository (or leave blank):
|
レシピの作成
# gitのインストール $ vi localhost.json { "run_list":[ "recipe[sample]" ] } $ vi solo.rb file_cashe_path "/tmp/chef-solo" cookbook_path ["/home/vagrant/chef-repo/cookbook"] |
ChefSoloを実行
$ sudo chef-solo -c solo.rb -j localhost.json Starting Chef Client, version 11.4.0 Compiling Cookbooks... Converging 3 resources Recipe: sample::default * package[httpd] action install - install version 2.2.15-30.el6.centos of package httpd * service[httpd] action enable - enable service service[httpd] * service[httpd] action start - start service service[httpd] * cookbook_file[/var/www/html/index.html] action create - create a new cookbook_file /var/www/html/index.html --- /tmp/chef-tempfile20140515-7393-tcwf1m 2014-05-15 15:54:20.639403562 +0000 +++ /home/vagrant/chef-repo/cookbook/sample/files/default/index.html 2014-05-15 15:47:15.061722443 +0000 @@ -0,0 +1,6 @@ +<html> +<body> + <h1>Hello, world!</h1> +</body> +</html> + Chef Client finished, 4 resources updated |
確認
ブラウザから確認
http://10.0.0.102/ |
おしまい。