chef-solo, vagrant に慣れるためにそれっぽいチュートリアルをやる
tutorial っぽいのがあったのでやってみる
http://vialstudios.com/guide-authoring-cookbooks.html
chef, chef-solo について
ここが詳しい。
http://knowledg.sakura.ad.jp/tech/867/
start
基本的に自分のメモなのであんまり参考にならないと思うけど残しておく。
- git install
- Install rbenv and ruby-build
- Install Ruby
- Install Berkshelf
- foodcritic を入れる。
- Install VirtualBox
- Install Vagrant
- Creating the Cookbook
/Users/vimtaku/vm/myface% berks cookbook myface --foodcritic
create myface/files/default
create myface/templates/default
create myface/attributes
create myface/definitions
create myface/libraries
create myface/providers
create myface/recipes
create myface/resources
create myface/recipes/default.rb
create myface/metadata.rb
create myface/LICENSE
create myface/README.md
create myface/Berksfile
create myface/Thorfile
create myface/chefignore
create myface/.gitignore
run git init from "./myface"
create myface/Gemfile
create myface/Vagrantfile
クックブックのスケルトンテンプレートを、 myface っていう名前で作成した。
- Prepare your virtual environment
- vendor/bundle にインストールする設定をやってなかったらやっておいたほうが良いかも
- bundle install
- Starting your virtual machine
- とりあえず言われたとおりにやってみろってことなのでやってみる
/Users/vimtaku/vm/myface/myface% bundle exec vagrant up
ringing machine 'default' up with 'virtualbox' provider...
[default] Box 'Berkshelf-CentOS-6.3-x86_64-minimal' was not found. Fetching box from specified URL for
the provider 'virtualbox'. Note that if the URL does not have
a box for this provider, you should interrupt Vagrant now and add
the box yourself. Otherwise Vagrant will attempt to download the
full box prior to discovering this error.
Downloading or copying the box...
Progress: 22% (Rate: 1045k/s, Estimated time remaining: 0:03:45)load: 1.56 cmd: curl 27613 waiting 0.84u 1.48s
Progress: 50% (Rate: 1068k/s, Estimated time remaining: 0:02:03)load: 1.47 cmd: curl 27613 waiting 1.76u 3.18s
Progress: 51% (Rate: 1147k/s, Estimated time remaining: 0:02:01)^U
Progress: 85% (Rate: 1061k/s, Estimated time remaining: 0:00:38)load: 1.27 cmd: curl 27613 waiting 2.72u 4.99s
Extracting box...te: 2251k/s, Estimated time remaining: 0:00:01)j
Successfully added box 'Berkshelf-CentOS-6.3-x86_64-minimal' with provider 'virtualbox'!
There are errors in the configuration of this machine. Please fix
the following errors and try again:
SSH:
* The following settings shouldn't exist: max_tries, timeout
- エラー。 ssh
- https://github.com/berkshelf/berkshelf/pull/856
- vagrant バージョンの違いによるものっぽい、削除して try
/Users/vimtaku/vm/myface/myface% bundle exec vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'Berkshelf-CentOS-6.3-x86_64-minimal'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[Berkshelf] This version of the Berkshelf plugin has not been fully tested on this version of Vagrant.
[Berkshelf] You should check for a newer version of vagrant-berkshelf.
[Berkshelf] If you encounter any errors with this version, please report them at https://github.com/RiotGames/vagrant-berkshelf/issues
[Berkshelf] You can also join the discussion in #berkshelf on Freenode.
[Berkshelf] Updating Vagrant's berkshelf: '/Users/vimtaku/.berkshelf/default/vagrant/berkshelf-20131227-27600-dzfcmn-default'
[Berkshelf] Using myface (0.1.0) from metadata
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Setting hostname...
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
[2013-12-27T09:05:00+00:00] INFO: *** Chef 10.14.2 ***
[2013-12-27T09:05:01+00:00] INFO: Setting the run_list to ["recipe[myface::default]"] from JSON
[2013-12-27T09:05:01+00:00] INFO: Run List is [recipe[myface::default]]
[2013-12-27T09:05:01+00:00] INFO: Run List expands to [myface::default]
[2013-12-27T09:05:01+00:00] INFO: Starting Chef Run for myface-berkshelf
[2013-12-27T09:05:01+00:00] INFO: Running start handlers
[2013-12-27T09:05:01+00:00] INFO: Start handlers complete.
[2013-12-27T09:05:01+00:00] INFO: Chef Run complete in 0.017946119 seconds
[2013-12-27T09:05:01+00:00] INFO: Running report handlers
[2013-12-27T09:05:01+00:00] INFO: Report handlers complete
/Users/vimtaku/vm/myface/myface% vim recipes/default.rb
artifact_deploy "myface" do
version "1.0.0"
artifact_location "http://dl.dropbox.com/u/31081437/myface-1.0.0.tar.gz"
deploy_to "/srv/myface"
owner "myface"
group "myface"
action :deploy
end
- provision command でもう一回 chef の provision を実行する。
- berkshelf vagrant plugin の 魔法によって依存関係を勝手に解決してくれる!
[Berkshelf] This version of the Berkshelf plugin has not been fully tested on this version of Vagrant.
[Berkshelf] You should check for a newer version of vagrant-berkshelf.
[Berkshelf] If you encounter any errors with this version, please report them at https://github.com/RiotGames/vagrant-berkshelf/issues
[Berkshelf] You can also join the discussion in #berkshelf on Freenode.
[Berkshelf] Updating Vagrant's berkshelf: '/Users/vimtaku/.berkshelf/default/vagrant/berkshelf-20131227-27600-dzfcmn-default'
[Berkshelf] Using myface (0.1.0)
[default] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
[2013-12-27T09:36:54+00:00] INFO: *** Chef 10.14.2 ***
[2013-12-27T09:36:54+00:00] INFO: Setting the run_list to ["recipe[myface::default]"] from JSON
[2013-12-27T09:36:54+00:00] INFO: Run List is [recipe[myface::default]]
[2013-12-27T09:36:54+00:00] INFO: Run List expands to [myface::default]
[2013-12-27T09:36:54+00:00] INFO: Starting Chef Run for myface-berkshelf
[2013-12-27T09:36:54+00:00] INFO: Running start handlers
[2013-12-27T09:36:54+00:00] INFO: Start handlers complete.
================================================================================
Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/myface/recipes/default.rb
================================================================================
NameError
---------
Cannot find a resource for artifact_deploy on centos version 6.3
Cookbook Trace:
---------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/myface/recipes/default.rb:9:in `from_file'
Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/myface/recipes/default.rb:
1: #
2: # Cookbook Name:: myface
3: # Recipe:: default
4: #
5: # Copyright (C) 2013 YOUR_NAME
6: #
7: # All rights reserved - Do Not Redistribute
8:
9: artifact_deploy "myface" do
[2013-12-27T09:36:55+00:00] ERROR: Running exception handlers
[2013-12-27T09:36:55+00:00] ERROR: Exception handlers complete
[2013-12-27T09:36:55+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-12-27T09:36:55+00:00] FATAL: NameError: Cannot find a resource for artifact_deploy on centos version 6.3
default[:myface][:user] = "myface"
default[:myface][:group] = "myface"
group "#{node['myface']['group']}"
user "#{node['myface']['group']}" do
group "#{node['myface']['group']}"
system true
shell "/bin/bash"
end
artifact_deploy "#{node['myface']['group']}" do
version "1.0.0"
artifact_location "/tmp/myface-1.0.0.tar.gz"
deploy_to "/srv/myface"
owner "#{node['myface']['user']}"
group "#{node['myface']['group']}"
action :deploy
end
require 'json'
file "/tmp/dna.json" do
content JSON.pretty_generate(node)
end