%admin ALL=(ALL) NOPASSWD: ALL
[~/chef-test]$ vagrant ssh-config --host melody Host melody HostName 192.168.38.129 User vagrant Port 22 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /Users/atsushi/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL [~/chef-test]$ vagrant ssh-config --host melody >> ~/.ssh/config
これは、vagrant が使う ethernet0 の IP アドレス。
ethernet1 に割り振った固定 IP アドレスに変更する必要がある
cf. Chef Vagrant + VMWare Fusion で 固定 IP
[~/chef-test]$ cat ~/.ssh/config Host melody HostName 192.168.38.100 User vagrant Port 22 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /Users/atsushi/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL [~/chef-test]$ ssh melody Last login: Sun Feb 2 14:37:45 2014 from 192.168.38.1 [vagrant@vagrant-centos-6 ~]$ uname -r 2.6.32-358.2.1.el6.x86_64 [vagrant@vagrant-centos-6 ~]$ exit logout Connection to 192.168.38.100 closed.
[~/chef-test]$ gem search knife-solo *** REMOTE GEMS *** knife-solo (0.4.1) knife-solo_data_bag (0.4.0) [~/chef-test]$ sudo gem install knife-solo ... 29 gems installed
[~/chef-test]$ knife solo init chef-repo Creating kitchen... Creating knife.rb in kitchen... Creating cupboards...
[~/chef-test]$ cd chef-repo/ [~/chef-test/chef-repo]$ git init Initialized empty Git repository in /Users/atsushi/chef-test/chef-repo/.git/ [~/chef-test/chef-repo]$ git add . [~/chef-test/chef-repo]$ git commit -m 'first commit'
[~/chef-test/chef-repo]$ 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
[~/chef-test]$ tree . ├── Vagrantfile └── chef-repo ├── cookbooks ├── data_bags ├── environments ├── nodes ├── roles └── site-cookbooks └── hello ├── CHANGELOG.md ├── README.md ├── attributes ├── definitions ├── files │   └── default ├── libraries ├── metadata.rb ├── providers ├── recipes │   └── default.rb ├── resources └── templates └── default 18 directories, 6 files
[~/chef-test/chef-repo]$ knife solo prepare melody WARNING: No knife configuration file found Bootstrapping Chef... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13347 100 13347 0 0 1932 0 0:00:06 0:00:06 --:--:-- 39961 Downloading Chef 11.8.2 for el... downloading https://www.opscode.com/chef/metadata?v=11.8.2&prerelease=false&p=el&pv=6&m=x86_64 to file /tmp/install.sh.2777/metadata.txt trying curl... url https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.8.2-1.el6.x86_64.rpm md5 10f3d0da82efa973fe91cc24a6a74549 sha256 044558f38d25bbf75dbd5790ccce892a38e5e9f2a091ed55367ab914fbd1cfed downloaded metadata file looks valid... downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.8.2-1.el6.x86_64.rpm to file /tmp/install.sh.2777/chef-11.8.2-1.el6.x86_64.rpm trying curl... Checksum compare with sha256sum succeeded. Installing Chef 11.8.2 installing with rpm... 警告: /tmp/install.sh.2777/chef-11.8.2-1.el6.x86_64.rpm: ヘッダ V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY 準備中... ########################################### [100%] 1:chef ########################################### [100%] Thank you for installing Chef! Generating node config 'nodes/melody.json'... [~/chef-test/chef-repo]$
[~/chef-test]$ tree . ├── Vagrantfile └── chef-repo ├── cookbooks ├── data_bags ├── environments ├── nodes │   └── melody.json ├── roles └── site-cookbooks └── hello ├── CHANGELOG.md ├── README.md ├── attributes ├── definitions ├── files │   └── default ├── libraries ├── metadata.rb ├── providers ├── recipes │   └── default.rb ├── resources └── templates └── default 18 directories, 6 files
[~/chef-test/chef-repo]$ cat nodes/melody.json {"run_list":[]}
# # Cookbook Name:: hello # Recipe:: default # # Copyright 2014, YOUR_COMPANY_NAME # # All rights reserved - Do Not Redistribute # log "Hello Knife!"
// melody.json { "run_list" : [ "recipe[hello]" ] }
[~/chef-test/chef-repo]$ knife solo cook melody Running Chef on melody... Checking Chef version... Uploading the kitchen... Generating solo config... Running Chef... Starting Chef Client, version 11.8.2 Compiling Cookbooks... Converging 1 resources Recipe: hello::default * log[Hello Knife!] action write Chef Client finished, 1 resources updated
コマンド | 動作 |
$ knife solo init chef-repo | リモート実行用の kitchen (repository) を作る |
$ knife solo prepare <host> | <host> に chef-solo をインストール |
$ knife solo cook <host> | <host> で recipe を実行する |
$ knife solo clean <host> | <host> から recipe を削除する |