gemsでknife-soloをインストール
c:\work\vagrant\lubuntu>gem install win32-process windows-pr --no-ri --no-rdoc Successfully installed win32-process-0.7.2 Successfully installed windows-pr-1.2.2 2 gems installed c:\work\vagrant\lubuntu>gem install knife-solo --no-ri --no-rdoc Thanks for installing knife-solo! If you run into any issues please let us know at: https://github.com/matschaffer/knife-solo/issues If you are upgrading knife-solo please uninstall any old versions by running `gem clean knife-solo` to avoid any errors. See http://bit.ly/CHEF-3255 for more information on the knife bug that causes this. Successfully installed knife-solo-0.3.0 1 gem installed
knife configureで設定で初期設定ファイルを作成
c:\work\vagrant\lubuntu>knife configure WARNING: No knife configuration file found Where should I put the config file? [C:/Users/abc/.chef/knife.rb] Please enter the chef server URL: [https://localhost:443] Please enter an existing username or clientname for the API: [abc] Please enter the validation clientname: [chef-validator] Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] Please enter the path to a chef repository (or leave blank): ***** You must place your client key in: C:/Users/abc/.chef/abc.pem Before running commands with Knife! ***** You must place your validation key in: c:/etc/chef-server/chef-validator.pem Before generating instance data with Knife! ***** Configuration file written to C:/Users/abc/.chef/knife.rb c:\work\vagrant\lubuntu>
knife設定をinit
c:\work\vagrant\lubuntu\knife>knife solo init chef-repo Creating kitchen... Creating knife.rb in kitchen... Creating cupboards...
gitでバージョン管理します。簡単な方法として、github for windowsを
https://github.com/
からダウンロードしてインストール
C:\work\vagrant\lubuntu [master +7 ~0 -0 | +1 ~0 -0 !]> git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: Vagrantfile # new file: knife/chef-repo/.chef/knife.rb # new file: knife/chef-repo/.gitignore # new file: knife/chef-repo/data_bags/.gitkeep # new file: knife/chef-repo/nodes/.gitkeep # new file: knife/chef-repo/roles/.gitkeep # new file: knife/chef-repo/site-cookbooks/.gitkeep # C:\work\vagrant\lubuntu [master +7 ~0 -0]> git commit -m 'init'
まず、knifeの初期化のためknife solo prepareを実行。これまでの手順だと、sshポートは2222なので、オプションで指定。
この手順で、nodes/localhost.jsonが自動生成されます。
c:\work\vagrant\lubuntu\knife\chef-repo>knife solo prepare vagrant@localhost -p 2222 DL is deprecated, please use Fiddle Bootstrapping Chef... Enter the password for vagrant@localhost: --2013-09-22 11:02:12-- https://www.opscode.com/chef/install.sh Resolving www.opscode.com (www.opscode.com)... 184.106.28.82 Connecting to www.opscode.com (www.opscode.com)|184.106.28.82|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 6790 (6.6K) [application/x-sh] Saving to: `install.sh' 100%[======================================>] 6,790 --.-K/s in 0s 2013-09-22 11:02:13 (627 MB/s) - `install.sh' saved [6790/6790] Downloading Chef 11.6.0 for ubuntu... Installing Chef 11.6.0 (Reading database ... 59514 files and directories currently installed.) Preparing to replace chef 11.6.0-1.ubuntu.12.04 (using .../chef_11.6.0_amd64.deb) ... Unpacking replacement chef ... Setting up chef (11.6.0-1.ubuntu.12.04) ... Thank you for installing Chef! Generating node config 'nodes/localhost.json'... c:\work\vagrant\lubuntu\knife\chef-repo>
サンプル的にcookbookを追加。site-cookbooksの方に、固有のcookbookを入れるのが推奨のようなので、
基本的にはこっち(site-cookbooks)をいじるようにする。
C:\work\vagrant\lubuntu\knife\chef-repo [master]> knife cookbook create hello -o site-cookbooks ** Creating cookbook hello ** Creating README for cookbook: hello ** Creating CHANGELOG for cookbook: hello ** Creating metadata for cookbook: hello C:\work\vagrant\lubuntu\knife\chef-repo [master +1 ~0 -0 !]> cd .\site-cookbooks C:\work\vagrant\lubuntu\knife\chef-repo\site-cookbooks [master +2 ~0 -0 !]> tree /f hello │ CHANGELOG.md │ metadata.rb │ README.md │ ├─attributes ├─definitions ├─files │ └─default ├─libraries ├─providers ├─recipes │ default.rb │ ├─resources └─templates └─default
site-cookbooks/hello/recipes/defaut.rbを編集。
log "Hello, Chef!" |
実行させるために
nodes/localhost.jsonを編集
{ "run_list":[ "hello" ] } |
いよいよ実行!
c:\work\vagrant\lubuntu\knife\chef-repo>knife solo cook vagrant@localhost -p 2222 DL is deprecated, please use Fiddle Running Chef on localhost... Checking Chef version... Enter the password for vagrant@localhost: Uploading the kitchen... ERROR: RuntimeError: Failed to launch command rsync -rl --chmod=ugo=rwX --rsh="ssh vagrant@localhost -p 2222" --delete --exclude 'revision-deploys' --exclude 'tmp' --exclude '.git' --exclude '.hg' --exclude '.svn' --exclude '.bzr' /cygdrive/c/work/vagrant/lubuntu/knife/chef-repo/cookbooks/ :~/chef-solo/cookbooks-1 c:\work\vagrant\lubuntu\knife\chef-repo>
rsyncコマンドがないと怒られました(´・ω・`)
めんどくさいのですが、cygwinをインストールします。
手順はこちら。
最終的に、コマンドプロンプトからrsyncとsshが実行できる状態になればOK
c:\work\vagrant\lubuntu\knife\chef-repo>rsync --version rsync version 3.0.9 protocol version 30 Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, no socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, no xattrs, iconv, symtimes rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details. c:\work\vagrant\lubuntu\knife\chef-repo>ssh --version ssh: unknown option -- - usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname [command] c:\work\vagrant\lubuntu\knife\chef-repo>
さて、再度実行してみます。
c:\work\vagrant\lubuntu\knife\chef-repo>knife solo cook vagrant@localhost -p 2222 DL is deprecated, please use Fiddle Running Chef on localhost... Checking Chef version... Enter the password for vagrant@localhost: Uploading the kitchen... vagrant@localhost's password: vagrant@localhost's password: vagrant@localhost's password: vagrant@localhost's password: vagrant@localhost's password: vagrant@localhost's password: vagrant@localhost's password: Generating solo config... vagrant@localhost's password: Running Chef... Starting Chef Client, version 11.6.0 Compiling Cookbooks... Converging 1 resources Recipe: hello::default * log[Hello, Chef!] action write Chef Client finished, 1 resources updated
キタ━(゚∀゚)━!とりあえずこれで、knfieを使って操作ができるようになった模様。
途中で、passwordを9回も入力されるように求められていて、これはウザいので後でなんとかする。
追記:sshで接続する方法
入門Chef Solo – Infrastructure as Code
posted with amazlet at 13.09.24
伊藤直也 (2013-03-11)
売り上げランキング: 421
売り上げランキング: 421