├── README.md ├── chapter01 ├── list1-01.txt ├── list1-02.txt └── list1-03.txt ├── chapter02 ├── fig2-01.txt ├── fig2-02.txt ├── fig2-03.txt ├── fig2-04.txt ├── fig2-05.txt ├── fig2-06.txt ├── fig2-07.txt ├── fig2-08.txt ├── fig2-09.txt ├── fig2-10.txt ├── fig2-11.txt ├── fig2-12.txt ├── fig2-13.txt ├── fig2-14.txt ├── fig2-15.txt ├── fig2-16.txt ├── fig2-17.txt ├── fig2-18.txt ├── fig2-19.txt ├── fig2-21.txt ├── fig2-22.txt ├── fig2-23.txt ├── fig2-24.txt ├── fig2-25.txt ├── fig2-26.txt ├── fig2-28.txt ├── fig2-29.txt ├── fig2-30.txt ├── fig2-31.txt ├── fig2-32.txt ├── fig2-33.txt ├── fig2-34.txt ├── fig2-36.txt ├── fig2-37.txt ├── list2-01.txt ├── list2-02.txt ├── list2-03.txt ├── list2-04.txt ├── list2-05.txt ├── list2-06.txt ├── list2-07.txt ├── list2-08.txt ├── list2-09.txt ├── list2-10.txt ├── list2-11.txt └── list2-12.txt ├── chapter03 ├── fig3-01.txt ├── fig3-02.txt ├── list3-01.txt ├── list3-02.txt ├── list3-03.txt ├── list3-04.txt ├── list3-05.txt ├── list3-06.txt ├── list3-07.txt ├── list3-08.txt ├── list3-09.txt ├── list3-10.txt ├── list3-11.txt ├── list3-12.txt ├── list3-13.txt ├── list3-14.txt ├── list3-15.txt ├── list3-16.txt ├── list3-17.txt ├── list3-18.txt ├── list3-19.txt ├── list3-20.txt ├── list3-21.txt ├── list3-22.txt ├── list3-23.txt ├── list3-24.txt ├── list3-25.txt ├── list3-26.txt ├── list3-27.txt ├── list3-28.txt ├── list3-29.txt ├── list3-30.txt ├── list3-31.txt ├── list3-32.txt ├── list3-33.txt ├── list3-34.txt ├── list3-35.txt ├── list3-36.txt ├── list3-37.txt ├── list3-38.txt ├── list3-39.txt ├── list3-40.txt ├── list3-41.txt ├── list3-42.txt ├── list3-43.txt ├── list3-44.txt ├── list3-45.txt └── list3-46.txt ├── chapter04 ├── fig4-01.txt ├── fig4-02.txt ├── fig4-03.txt ├── fig4-05.txt ├── fig4-06.txt ├── list4-01.txt ├── list4-02.txt ├── list4-03.txt ├── list4-04.txt ├── list4-05.txt ├── list4-06.txt ├── list4-07.txt ├── list4-08.txt ├── list4-09.txt ├── list4-10.txt ├── list4-11.txt ├── list4-12.txt ├── list4-13.txt ├── list4-14.txt └── list4-15.txt ├── chapter05 ├── list5.1 │ └── Vagrantfile ├── list5.3 │ ├── base.sh │ ├── ks.cfg │ └── template.json └── list5.7 │ └── Vagrantfile ├── chapter06 ├── Berksfile ├── Gemfile ├── Vagrantfile ├── Vagrantfile.dbmaster ├── list6.1 │ └── Gemfile ├── list6.10 │ └── default.rb ├── list6.11 │ └── default.rb ├── list6.12 │ └── Vagrantfile ├── list6.13 │ └── default.rb ├── list6.14 │ └── index.php ├── list6.15 │ └── php55.rb ├── list6.16 │ └── Vagrantfile ├── list6.18 │ └── Berksfile ├── list6.19 │ └── Vagrantfile ├── list6.2 │ └── default.rb ├── list6.20 │ └── default.rb ├── list6.21 │ └── default.rb ├── list6.22 │ └── .bash_profile.erb ├── list6.23 │ └── default.rb ├── list6.24 │ └── default.rb ├── list6.25 │ └── nginx.conf.erb ├── list6.26 │ └── Vagrantfile ├── list6.27 │ └── Gemfile ├── list6.28 │ └── unicorn.rb ├── list6.29 │ └── Berksfile ├── list6.3 │ └── Berksfile ├── list6.30 │ └── default.rb ├── list6.31 │ └── default.rb ├── list6.32 │ └── Vagrantfile ├── list6.33 │ └── Berksfile ├── list6.34 │ └── default.rb ├── list6.35 │ └── default.rb ├── list6.36 │ └── Vagrantfile ├── list6.37 │ └── Vagrantfile ├── list6.38 │ └── my.cnf.erb ├── list6.39 │ └── create_slave_user.sql.erb ├── list6.4 │ └── Vagrantfile ├── list6.40 │ └── default.rb ├── list6.41 │ └── daily_slave_backup.sh.erb ├── list6.42 │ └── default.rb ├── list6.43 │ └── Berksfile ├── list6.44 │ └── site-cookbooks │ │ └── fluentd │ │ ├── recipes │ │ └── default.rb │ │ └── templates │ │ └── default │ │ └── fluent.conf.erb ├── list6.45 │ └── default.rb ├── list6.46 │ └── Vagrantfile ├── list6.5 │ └── Vagrantfile ├── list6.6 │ └── default.rb ├── list6.7 │ └── Vagrantfile ├── list6.8 │ └── Berksfile ├── list6.9 │ └── nginx.conf.erb └── site-cookbooks │ ├── fluentd │ ├── CHANGELOG.md │ ├── README.md │ ├── attributes │ │ └── default.rb │ ├── metadata.rb │ ├── recipes │ │ └── default.rb │ └── templates │ │ └── default │ │ └── fluent.conf.erb │ ├── mysql │ ├── CHANGELOG.md │ ├── README.md │ ├── attributes │ │ └── default.rb │ ├── metadata.rb │ ├── recipes │ │ └── default.rb │ └── templates │ │ └── default │ │ ├── create_slave_user.sql.erb │ │ ├── daily_slave_backup.sh.erb │ │ └── my.cnf.erb │ ├── nginx │ ├── CHANGELOG.md │ ├── README.md │ ├── attributes │ │ └── default.rb │ ├── metadata.rb │ ├── recipes │ │ └── default.rb │ └── templates │ │ └── default │ │ └── nginx.conf.erb │ ├── nodejs │ ├── CHANGELOG.md │ ├── README.md │ ├── attributes │ │ └── default.rb │ ├── metadata.rb │ └── recipes │ │ └── default.rb │ ├── php-env │ ├── CHANGELOG.md │ ├── README.md │ ├── metadata.rb │ └── recipes │ │ ├── default.rb │ │ └── php55.rb │ └── ruby-env │ ├── CHANGELOG.md │ ├── README.md │ ├── attributes │ └── default.rb │ ├── metadata.rb │ ├── recipes │ └── default.rb │ └── templates │ └── default │ └── .bash_profile.erb ├── chapter07 ├── 7.2 │ └── analog │ │ ├── .gitignore │ │ ├── .kitchen.yml │ │ ├── Berksfile │ │ ├── CHANGELOG.md │ │ ├── Gemfile │ │ ├── LICENSE │ │ ├── README.md │ │ ├── Vagrantfile.erb │ │ ├── files │ │ └── default │ │ │ └── tests │ │ │ └── minitest │ │ │ ├── default_test.rb │ │ │ └── support │ │ │ └── empty │ │ ├── metadata.rb │ │ ├── recipes │ │ └── default.rb │ │ └── test │ │ └── integration │ │ └── default │ │ ├── bats │ │ └── default_test.bats │ │ ├── minitest │ │ └── default_spec.rb │ │ └── serverspec │ │ ├── localhost │ │ └── default_spec.rb │ │ └── spec_helper.rb └── 7.3 │ └── acme-trac │ ├── .gitignore │ ├── .kitchen.yml │ ├── Berksfile │ ├── CHANGELOG.md │ ├── Gemfile │ ├── README.md │ ├── metadata.rb │ ├── recipes │ └── default.rb │ ├── templates │ └── default │ │ ├── http.erb │ │ └── ssh.erb │ └── test │ └── integration │ └── default │ └── serverspec │ └── localhost │ └── default_spec.rb ├── chapter08 ├── list8-01.txt ├── list8-02.txt ├── list8-03.txt ├── list8-04.txt ├── list8-05.txt ├── list8-06.txt ├── list8-07.txt ├── list8-08.txt ├── list8-09.txt ├── list8-10.txt ├── list8-11.txt ├── list8-12.txt ├── list8-13.txt ├── list8-14.txt ├── list8-15.txt ├── list8-16.txt ├── list8-17.txt ├── list8-18.txt ├── list8-19.txt ├── list8-20.txt ├── list8-21.txt ├── list8-22.txt ├── list8-23.txt ├── list8-24.txt ├── list8-25.txt ├── list8-26.txt ├── list8-27.txt ├── list8-28.txt ├── list8-29.txt ├── list8-30.txt ├── list8-31.txt ├── list8-32.txt └── list8-33.txt ├── chapter09 ├── list09-01.txt ├── list09-02.txt ├── list09-03.txt ├── list09-05.txt ├── list09-06.txt └── list09-07.txt └── chapter10 ├── list10-01.txt ├── list10-02.txt ├── list10-03.txt └── list10-04.txt /README.md: -------------------------------------------------------------------------------- 1 | # 『Chef実践入門』サンプルコードのダウンロード 2 | 3 | ## 書籍について 4 | - 吉羽龍太郎、安藤祐介、伊藤直也、菅井祐太朗、並河祐貴著 5 | - 『Chef実践入門』(WEB+DB PRESS plus シリーズ) 6 | - A5判/392ページ 7 | - 技術評論社、2014年 8 | 9 | ## 目次 10 | - 第1章:DevOpsの潮流とChef 11 | - 第2章:Chef Soloによるローカル開発環境の自動構築 12 | - 第3章:レシピの書き方 13 | - 第4章:クックブックの活用 14 | - 第5章:Vagrantによるクックブック開発環境の構築 15 | - 第6章:アプリケーション実行環境の自動構築 16 | - 第7章:テスト駆動インフラ構築 17 | - 第8章:Chefをより活用するための注意点 18 | - 第9章:Chef Serverによる本番環境の構築と運用 19 | - 第10章:Chef Serverによる大規模システムの構築と運用 20 | - Appendix A:コマンドチートシート 21 | - Appendix B:クックブックチートシート 22 | 23 | ## サポートページ 24 | http://gihyo.jp/book/2014/978-4-7741-6500-4 25 | 26 | ## WEB+DB PRESS plusシリーズ 27 | http://wdpress.gihyo.jp/plus 28 | 29 | ## ご注意 30 | 本サンプルコード、本書の内容に基づく運用結果について、著者、ソフトウェアの開発元および提供元、株式会社技術評論社は一切の責任を負いかねますので、あらかじめご了承ください。 31 | 32 | ## サンプルコードのライセンス 33 | サンプルコードはMITライセンスで配布しています。 34 | 35 | http://opensource.org/licenses/mit-license.php 36 | 37 | ## 各章で登場したコード 38 | - 各章で登場したコードは、リストごとにテキストを用意しています。 39 | - 章によっては紙幅の都合上本書に掲載できなかったコードも用意しています。 40 | 41 | ## Gitを利用せずにダウンロードするには 42 | 本ページ右部にある「Download ZIP」ボタンを押すと、最新のソースコードがダウンロードできます。Gitを利用していない方はこちらをご利用ください。 43 | 44 | ## 本書についてのご質問 45 | 本書についてのお問い合わせは、以下のページからお願いします。 46 | 47 | https://gihyo.jp/site/inquiry/book?ISBN=978-4-7741-6500-4 48 | 49 | ## 正誤表 50 | 本書の正誤情報は以下のページで公開しています。 51 | 52 | http://gihyo.jp/book/2014/978-4-7741-6500-4/support#supportApology 53 | -------------------------------------------------------------------------------- /chapter01/list1-01.txt: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | yum install -y httpd httpd-devel php php-mbstring php-pdo php-mysql mysql-server 3 | /sbin/chkconfig --level 2345 httpd on 4 | /sbin/chkconfig --level 2345 mysqld on 5 | /etc/rc.d/init.d/mysqld start 6 | /etc/rc.d/init.d/httpd start 7 | -------------------------------------------------------------------------------- /chapter01/list1-02.txt: -------------------------------------------------------------------------------- 1 | desc "Capistranoで必要なパッケージをインストールする例" 2 | task :install_amp, roles => :web do 3 | run <<-CMD 4 | sudo yum install -y httpd httpd-devel php php-mbstring php-pdo php-mysql mysql-server && 5 | sudo /sbin/chkconfig --level 2345 httpd on && 6 | sudo /sbin/chkconfig --level 2345 mysqld on && 7 | sudo /etc/rc.d/init.d/mysqld start && 8 | sudo /etc/rc.d/init.d/httpd start 9 | CMD 10 | end 11 | -------------------------------------------------------------------------------- /chapter01/list1-03.txt: -------------------------------------------------------------------------------- 1 | %w{httpd httpd-devel php php-mbstring php-pdo php-mysql mysql-server}.each do |p| 2 | package p do 3 | action :install 4 | end 5 | end 6 | 7 | service "httpd" do 8 | action [:enable, :restart] 9 | supports :status => true, :start => true, :stop => true, :restart => true 10 | end 11 | 12 | service "mysqld" do 13 | action [:enable, :restart] 14 | supports :status => true, :start => true, :stop => true, :restart => true 15 | end 16 | -------------------------------------------------------------------------------- /chapter02/fig2-01.txt: -------------------------------------------------------------------------------- 1 | $ vagrant init centos 2 | $ vagrant up 3 | -------------------------------------------------------------------------------- /chapter02/fig2-02.txt: -------------------------------------------------------------------------------- 1 | $ vagrant -v 2 | Vagrant 1.5.1 3 | -------------------------------------------------------------------------------- /chapter02/fig2-03.txt: -------------------------------------------------------------------------------- 1 | $ vagrant box add opscode-centos-6.5 http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box 2 | -------------------------------------------------------------------------------- /chapter02/fig2-04.txt: -------------------------------------------------------------------------------- 1 | $ vagrant init opscode-centos-6.5 2 | $ vagrant up 3 | -------------------------------------------------------------------------------- /chapter02/fig2-05.txt: -------------------------------------------------------------------------------- 1 | $ vagrant up 2 | Bringing machine 'default' up with 'virtualbox' provider... 3 | ==> default: Importing base box 'opscode-centos-6.5'... 4 | ==> default: Matching MAC address for NAT networking... 5 | 略 6 | ==> default: Machine booted and ready! 7 | ==> default: Checking for guest additions in VM... 8 | ==> default: Mounting shared folders... 9 | default: /vagrant => /Users/naoya/vm/chapter02 10 | -------------------------------------------------------------------------------- /chapter02/fig2-06.txt: -------------------------------------------------------------------------------- 1 | $ vagrant ssh 2 | Last login: Sat May 24 04:55:22 2014 from 10.0.2.2 3 | [vagrant@localhost ~]$ cat /etc/redhat-release 4 | CentOS release 6.5 (Final) 5 | -------------------------------------------------------------------------------- /chapter02/fig2-07.txt: -------------------------------------------------------------------------------- 1 | $ vagrant ssh-config --host webdb >> ~/.ssh/config 2 | -------------------------------------------------------------------------------- /chapter02/fig2-08.txt: -------------------------------------------------------------------------------- 1 | $ vagrant halt 2 | $ vagrant up 3 | -------------------------------------------------------------------------------- /chapter02/fig2-09.txt: -------------------------------------------------------------------------------- 1 | $ curl -L https://www.opscode.com/chef/install.sh | sudo bash 2 | -------------------------------------------------------------------------------- /chapter02/fig2-10.txt: -------------------------------------------------------------------------------- 1 | $ chef-solo -v 2 | Chef: 11.10.4 3 | -------------------------------------------------------------------------------- /chapter02/fig2-11.txt: -------------------------------------------------------------------------------- 1 | $ sudo knife cookbook create hello -o /var/chef/cookbooks 2 | -------------------------------------------------------------------------------- /chapter02/fig2-12.txt: -------------------------------------------------------------------------------- 1 | $ sudo chef-solo -o hello 2 | [2014-03-24T12:21:06+00:00] WARN: ***************************************** 3 | [2014-03-24T12:21:06+00:00] WARN: Did not find config file: /etc/chef/solo.rb, using command line options. 4 | [2014-03-24T12:21:06+00:00] WARN: ***************************************** 5 | Starting Chef Client, version 11.10.4 6 | [2014-03-24T12:21:08+00:00] WARN: Run List override has been provided. 7 | [2014-03-24T12:21:08+00:00] WARN: Original Run List: [] 8 | [2014-03-24T12:21:08+00:00] WARN: Overridden Run List: [recipe[hello]] 9 | Compiling Cookbooks... 10 | Converging 1 resources 11 | Recipe: hello::default 12 | * log[Hello, World!] action write 13 | 14 | Running handlers: 15 | Running handlers complete 16 | 17 | Chef Client finished, 1/1 resources updated in 1.713308761 seconds 18 | -------------------------------------------------------------------------------- /chapter02/fig2-13.txt: -------------------------------------------------------------------------------- 1 | $ sudo knife cookbook create dstat -o /var/chef/cookbooks 2 | -------------------------------------------------------------------------------- /chapter02/fig2-14.txt: -------------------------------------------------------------------------------- 1 | $ sudo chef-solo -o hello,dstat 2 | ... 3 | Compiling Cookbooks... 4 | Converging 2 resources 5 | Recipe: hello::default 6 | * log[Hello, World!] action write 7 | 8 | Recipe: dstat::default 9 | * package[dstat] action install 10 | - install version 0.7.0-1.el6 of package dstat 11 | 12 | Running handlers: 13 | Running handlers complete 14 | 15 | Chef Client finished, 2/2 resources updated in 31.512805112 seconds 16 | -------------------------------------------------------------------------------- /chapter02/fig2-15.txt: -------------------------------------------------------------------------------- 1 | $ rpm -q dstat 2 | dstat-0.7.0-1.el6.noarch 3 | -------------------------------------------------------------------------------- /chapter02/fig2-16.txt: -------------------------------------------------------------------------------- 1 | $ sudo chef-solo -o hello,dstat 2 | ... 3 | Compiling Cookbooks... 4 | Converging 2 resources 5 | Recipe: hello::default 6 | * log[Hello, World!] action write 7 | 8 | Recipe: dstat::default 9 | * package[dstat] action install (up to date) 10 | 11 | Running handlers: 12 | Running handlers complete 13 | 14 | Chef Client finished, 1/2 resources updated in 4.24875853 seconds 15 | -------------------------------------------------------------------------------- /chapter02/fig2-17.txt: -------------------------------------------------------------------------------- 1 | $ gem install knife-solo 2 | -------------------------------------------------------------------------------- /chapter02/fig2-18.txt: -------------------------------------------------------------------------------- 1 | $ gem install berkshelf 2 | -------------------------------------------------------------------------------- /chapter02/fig2-19.txt: -------------------------------------------------------------------------------- 1 | $ knife solo init . 2 | -------------------------------------------------------------------------------- /chapter02/fig2-21.txt: -------------------------------------------------------------------------------- 1 | $ knife solo bootstrap webdb 2 | -------------------------------------------------------------------------------- /chapter02/fig2-22.txt: -------------------------------------------------------------------------------- 1 | $ knife cookbook create dstat -o site-cookbooks 2 | -------------------------------------------------------------------------------- /chapter02/fig2-23.txt: -------------------------------------------------------------------------------- 1 | $ knife solo cook webdb 2 | Running Chef on webdb... 3 | Checking Chef version... 4 | Installing Berkshelf cookbooks to 'cookbooks'... 5 | Uploading the kitchen... 6 | Generating solo config... 7 | Running Chef... 8 | Starting Chef Client, version 11.10.4 9 | Compiling Cookbooks... 10 | Converging 1 resources 11 | Recipe: dstat::default 12 | * package[dstat] action install (up to date) 13 | 14 | Running handlers: 15 | Running handlers complete 16 | 17 | Chef Client finished, 0/1 resources updated in 4.360414841 seconds 18 | -------------------------------------------------------------------------------- /chapter02/fig2-24.txt: -------------------------------------------------------------------------------- 1 | $ knife cookbook create apache -o site-cookbooks 2 | $ knife cookbook create mysql -o site-cookbooks 3 | -------------------------------------------------------------------------------- /chapter02/fig2-25.txt: -------------------------------------------------------------------------------- 1 | $ knife solo cook webdb 2 | -------------------------------------------------------------------------------- /chapter02/fig2-26.txt: -------------------------------------------------------------------------------- 1 | $ vagrant ssh 2 | $ ps auxw | egrep "(httpd|mysql)" 3 | -------------------------------------------------------------------------------- /chapter02/fig2-28.txt: -------------------------------------------------------------------------------- 1 | $ ls /vagrant 2 | Berksfile Vagrantfile data_bags nodes site-cookbooks 3 | Berksfile.lock cookbooks environments roles 4 | -------------------------------------------------------------------------------- /chapter02/fig2-29.txt: -------------------------------------------------------------------------------- 1 | $ cp /etc/httpd/conf/httpd.conf /vagrant/site-cookbooks/apache/templates/default/httpd.conf.erb 2 | -------------------------------------------------------------------------------- /chapter02/fig2-30.txt: -------------------------------------------------------------------------------- 1 | $ knife solo cook webdb 2 | Recipe: apache::default 3 | 略 4 | * template[httpd.conf] action create 5 | - update content in file /etc/httpd/conf/httpd.conf from beb8a6 to 2b811c 6 | --- /etc/httpd/conf/httpd.conf 2013-08-02 11:59:13.000000000 +0000 7 | +++ /tmp/chef-rendered-template20140324-7937-1qnvglq 2014-03-24 10:59:04.279070256 +0000 8 | @@ -274,6 +274,7 @@ 9 | # redirections work in a sensible way. 10 | # 11 | #ServerName www.example.com:80 12 | +ServerName webdb:80 13 | 14 | # 15 | # UseCanonicalName: Determines how Apache constructs self-referencing 16 | 17 | Recipe: apache::default 18 | * service[httpd] action reload 19 | - reload service service[httpd] 20 | -------------------------------------------------------------------------------- /chapter02/fig2-31.txt: -------------------------------------------------------------------------------- 1 | $ vagrant destroy -f 2 | -------------------------------------------------------------------------------- /chapter02/fig2-32.txt: -------------------------------------------------------------------------------- 1 | $ vagrant up 2 | $ vagrant ssh 3 | -------------------------------------------------------------------------------- /chapter02/fig2-33.txt: -------------------------------------------------------------------------------- 1 | $ knife solo bootstrap webdb 2 | -------------------------------------------------------------------------------- /chapter02/fig2-34.txt: -------------------------------------------------------------------------------- 1 | $ git init 2 | $ git add . 3 | $ git commit -m 'First commit' 4 | -------------------------------------------------------------------------------- /chapter02/fig2-36.txt: -------------------------------------------------------------------------------- 1 | $ knife solo cook myserver.example.com 2 | -------------------------------------------------------------------------------- /chapter02/fig2-37.txt: -------------------------------------------------------------------------------- 1 | $ knife solo cook naoya@myserver.example.com -i ~/.ssh/id_rsa 2 | -------------------------------------------------------------------------------- /chapter02/list2-01.txt: -------------------------------------------------------------------------------- 1 | 略 2 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 3 | 略 4 | config.vm.box = "opscode-centos-6.5" 5 | 略 6 | config.vm.network :private_network, ip: "192.168.33.10" 7 | 略 8 | end 9 | -------------------------------------------------------------------------------- /chapter02/list2-02.txt: -------------------------------------------------------------------------------- 1 | package "git" do 2 | action :install 3 | end 4 | -------------------------------------------------------------------------------- /chapter02/list2-03.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: hello 3 | # Recipe:: default 4 | # 5 | # Copyright 2014, YOUR_COMPANY_NAME 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | log "Hello, World!" 10 | -------------------------------------------------------------------------------- /chapter02/list2-04.txt: -------------------------------------------------------------------------------- 1 | package "dstat" do 2 | action :install 3 | end 4 | -------------------------------------------------------------------------------- /chapter02/list2-05.txt: -------------------------------------------------------------------------------- 1 | package "dstat" do 2 | action :install 3 | end 4 | -------------------------------------------------------------------------------- /chapter02/list2-06.txt: -------------------------------------------------------------------------------- 1 | {"run_list":[]} 2 | -------------------------------------------------------------------------------- /chapter02/list2-07.txt: -------------------------------------------------------------------------------- 1 | { 2 | "run_list":[ 3 | "recipe[dstat]" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /chapter02/list2-08.txt: -------------------------------------------------------------------------------- 1 | { 2 | "run_list":[ 3 | "recipe[dstat]", 4 | "recipe[apache]", 5 | "recipe[mysql]" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /chapter02/list2-09.txt: -------------------------------------------------------------------------------- 1 | package "httpd" do 2 | action :install 3 | end 4 | 5 | service "httpd" do 6 | action [ :enable, :start ] 7 | end 8 | -------------------------------------------------------------------------------- /chapter02/list2-10.txt: -------------------------------------------------------------------------------- 1 | package "mysql-server" do 2 | action :install 3 | end 4 | 5 | service "mysqld" do 6 | action [ :enable, :start ] 7 | end 8 | -------------------------------------------------------------------------------- /chapter02/list2-11.txt: -------------------------------------------------------------------------------- 1 | template "httpd.conf" do 2 | path "/etc/httpd/conf/httpd.conf" 3 | owner "root" 4 | group "root" 5 | mode 0644 6 | notifies :reload, 'service[httpd]' 7 | end 8 | -------------------------------------------------------------------------------- /chapter02/list2-12.txt: -------------------------------------------------------------------------------- 1 | package "dstat" do 2 | action :install 3 | end 4 | -------------------------------------------------------------------------------- /chapter03/fig3-01.txt: -------------------------------------------------------------------------------- 1 | $ ohai | head 2 | { 3 | "languages": { 4 | "ruby": { 5 | "platform": "x86_64-linux", 6 | "version": "1.8.7", 7 | "release_date": "2011-06-30", 8 | "target": "x86_64-redhat-linux-gnu", 9 | "target_cpu": "x86_64", 10 | -------------------------------------------------------------------------------- /chapter03/fig3-02.txt: -------------------------------------------------------------------------------- 1 | $ ohai platform 2 | [ 3 | "centos" 4 | ] 5 | -------------------------------------------------------------------------------- /chapter03/list3-01.txt: -------------------------------------------------------------------------------- 1 | template "httpd.conf" do 2 | path "/etc/httpd/conf/httpd.conf" 3 | owner "root" 4 | group "root" 5 | mode 0644 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-02.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: td-agent 3 | # Recipe:: default 4 | # 5 | # Copyright 2011, Treasure Data, Inc. 6 | # 7 | 8 | group 'td-agent' do 9 | group_name 'td-agent' 10 | gid 403 11 | action :create 12 | end 13 | 14 | user 'td-agent' do 15 | comment 'td-agent' 16 | uid 403 17 | group 'td-agent' 18 | home '/var/run/td-agent' 19 | shell '/bin/false' 20 | password nil 21 | supports :manage_home => true 22 | action [:create, :manage] 23 | end 24 | 25 | directory '/etc/td-agent/' do 26 | owner 'td-agent' 27 | group 'td-agent' 28 | mode '0755' 29 | action :create 30 | end 31 | 32 | case node['platform'] 33 | when "ubuntu" 34 | dist = node['lsb']['codename'] 35 | source = (dist == 'precise') ? "http://packages.treasure-data.com/precise/" : "http://packages.treasure-data.com/debian/" 36 | apt_repository "treasure-data" do 37 | uri source 38 | distribution dist 39 | components ["contrib"] 40 | action :add 41 | end 42 | when "centos", "redhat" 43 | yum_repository "treasure-data" do 44 | url "http://packages.treasure-data.com/redhat/$basearch" 45 | action :add 46 | end 47 | end 48 | 49 | template "/etc/td-agent/td-agent.conf" do 50 | mode "0644" 51 | source "td-agent.conf.erb" 52 | end 53 | 54 | package "td-agent" do 55 | options value_for_platform( 56 | ["ubuntu", "debian"] => {"default" => "-f --force-yes"}, 57 | "default" => nil 58 | ) 59 | action :upgrade 60 | end 61 | 62 | service "td-agent" do 63 | action [ :enable, :start ] 64 | subscribes :restart, resources(:template => "/etc/td-agent/td-agent.conf") 65 | end 66 | -------------------------------------------------------------------------------- /chapter03/list3-03.txt: -------------------------------------------------------------------------------- 1 | group 'td-agent' do 2 | group_name 'td-agent' 3 | gid 403 4 | action :create 5 | end 6 | 7 | user 'td-agent' do 8 | comment 'td-agent' 9 | uid 403 10 | group 'td-agent' 11 | home '/var/run/td-agent' 12 | shell '/bin/false' 13 | password nil 14 | supports :manage_home => true 15 | action [:create, :manage] 16 | end 17 | -------------------------------------------------------------------------------- /chapter03/list3-04.txt: -------------------------------------------------------------------------------- 1 | directory '/etc/td-agent/' do 2 | owner 'td-agent' 3 | group 'td-agent' 4 | mode '0755' 5 | action :create 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-05.txt: -------------------------------------------------------------------------------- 1 | case node['platform'] 2 | when "ubuntu" 3 | dist = node['lsb']['codename'] 4 | source = (dist == 'precise') ? "http://packages.treasure-data.com/precise/" : "http://packages.treasure-data.com/debian/" 5 | apt_repository "treasure-data" do 6 | uri source 7 | distribution dist 8 | components ["contrib"] 9 | action :add 10 | end 11 | when "centos", "redhat" 12 | yum_repository "treasure-data" do 13 | url "http://packages.treasure-data.com/redhat/$basearch" 14 | action :add 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /chapter03/list3-06.txt: -------------------------------------------------------------------------------- 1 | template "/etc/td-agent/td-agent.conf" do 2 | mode "0644" 3 | source "td-agent.conf.erb" 4 | end 5 | 6 | package "td-agent" do 7 | options "-f --force-yes" 8 | action :upgrade 9 | end 10 | 11 | service "td-agent" do 12 | action [ :enable, :start ] 13 | subscribes :restart, resources(:template => "/etc/td-agent/td-agent.conf") 14 | end 15 | -------------------------------------------------------------------------------- /chapter03/list3-07.txt: -------------------------------------------------------------------------------- 1 | package "git" do 2 | action :install 3 | end 4 | -------------------------------------------------------------------------------- /chapter03/list3-08.txt: -------------------------------------------------------------------------------- 1 | %w{gcc make git}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-09.txt: -------------------------------------------------------------------------------- 1 | package "perl" do 2 | action :install 3 | version "5.10.1" 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-10.txt: -------------------------------------------------------------------------------- 1 | package "perl" do 2 | action :remove 3 | end 4 | -------------------------------------------------------------------------------- /chapter03/list3-11.txt: -------------------------------------------------------------------------------- 1 | package "tar" do 2 | action :install 3 | source "/tmp/tar-1.16.1-1.rpm" 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-12.txt: -------------------------------------------------------------------------------- 1 | package "debian-archive-keyring" do 2 | action :install 3 | options "--force-yes" 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-13.txt: -------------------------------------------------------------------------------- 1 | service "httpd" do 2 | action [ :enable, :start ] 3 | supports :status => true, :restart => true, :reload => true 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-14.txt: -------------------------------------------------------------------------------- 1 | service "httpd" do 2 | supports :status => true, :restart => true, :reload => true 3 | action [ :enable, :start ] 4 | end 5 | 6 | template "httpd.conf" do 7 | path "/etc/httpd/conf/httpd.conf" 8 | owner "root" 9 | group "root" 10 | mode 0644 11 | notifies :reload, 'service[httpd]' 12 | end 13 | -------------------------------------------------------------------------------- /chapter03/list3-15.txt: -------------------------------------------------------------------------------- 1 | service "td-agent" do 2 | supports :status => true, :restart => true, :reload => true 3 | action [ :enable, :start ] 4 | subscribes :restart, "template[td-agent.conf]" 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-16.txt: -------------------------------------------------------------------------------- 1 | template "httpd.conf" do 2 | path "/etc/httpd/conf/httpd.conf" 3 | source "httpd.conf.erb" 4 | owner "root" 5 | group "root" 6 | mode 0644 7 | end 8 | -------------------------------------------------------------------------------- /chapter03/list3-17.txt: -------------------------------------------------------------------------------- 1 | template "/etc/httpd/conf/httpd.conf" do 2 | source "httpd.conf.erb" 3 | owner "root" 4 | group "root" 5 | mode 0644 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-18.txt: -------------------------------------------------------------------------------- 1 | template "/etc/httpd/conf/httpd.conf" do 2 | owner "root" 3 | group "root" 4 | mode 0644 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-19.txt: -------------------------------------------------------------------------------- 1 | user "naoya" do 2 | comment "naoya" 3 | home "/home/naoya" 4 | shell "/bin/bash" 5 | password nil 6 | supports :manage_home => true 7 | action [:create, :manage] 8 | end 9 | -------------------------------------------------------------------------------- /chapter03/list3-20.txt: -------------------------------------------------------------------------------- 1 | group "webdb" do 2 | gid 999 3 | members ['naoya', 'inao'] 4 | action :create 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-21.txt: -------------------------------------------------------------------------------- 1 | group "admin" do 2 | action :modify 3 | members [ 'dikeda' ] 4 | append true 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-22.txt: -------------------------------------------------------------------------------- 1 | directory '/etc/td-agent/' do 2 | owner 'td-agent' 3 | group 'td-agent' 4 | mode '0755' 5 | action :create 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-23.txt: -------------------------------------------------------------------------------- 1 | cookbook_file "#{Chef::Config[:file_cache_path]}/supervisor-3.0a12-2.el6.noarch.rpm" do 2 | mode 00644 3 | end 4 | -------------------------------------------------------------------------------- /chapter03/list3-24.txt: -------------------------------------------------------------------------------- 1 | cookbook_file "#{Chef::Config[:file_cache_path]}/supervisor-3.0.rpm" do 2 | source "supervisor-3.0a12-2.el6.noarch.rpm" 3 | mode 00644 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-25.txt: -------------------------------------------------------------------------------- 1 | cookbook_file "#{Chef::Config[:file_cache_path]}/supervisor-3.0a12-2.el6.noarch.rpm" do 2 | source "supervisor-3.0a12-2.el6.noarch.rpm" 3 | mode 00644 4 | checksum "012f34db9e08f67e6060d7ab8d16c264b93cba82fb65b52090f0d342c406fbf7" 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-26.txt: -------------------------------------------------------------------------------- 1 | ifconfig "192.168.30.1" do 2 | device "eth0" 3 | end 4 | -------------------------------------------------------------------------------- /chapter03/list3-27.txt: -------------------------------------------------------------------------------- 1 | mount "/mnt/volume1" do 2 | device "volume1" 3 | device_type :label 4 | fstype "xfs" 5 | options "rw" 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-28.txt: -------------------------------------------------------------------------------- 1 | bash "install perlbrew" do 2 | user 'vagrant' 3 | group 'vagrant' 4 | cwd '/home/vagrant' 5 | environment "HOME" => '/home/vagrant' 6 | code <<-EOC 7 | curl -kL http://install.perlbrew.pl | bash 8 | EOC 9 | creates "/home/vagrant/perl5/perlbrew/bin/perlbrew" 10 | end 11 | -------------------------------------------------------------------------------- /chapter03/list3-29.txt: -------------------------------------------------------------------------------- 1 | bash "install-rubybuild" do 2 | not_if 'which ruby-build' 3 | code <<-EOC 4 | cd /tmp/ruby-build 5 | ./install.sh 6 | EOC 7 | end 8 | -------------------------------------------------------------------------------- /chapter03/list3-30.txt: -------------------------------------------------------------------------------- 1 | not_if <<-EOC, :user => 'vagrant', :environment => { 'HOME' => '/home/vagrant' } 2 | 略 3 | EOC 4 | -------------------------------------------------------------------------------- /chapter03/list3-31.txt: -------------------------------------------------------------------------------- 1 | bash 'create swapfile' do (d1) 2 | code <<-EOC 3 | dd if=/dev/zero of=/swap.img bs=1M count=2048 && 4 | chmod 600 /swap.img 5 | mkswap /swap.img 6 | EOC 7 | only_if { not node[:ec2].nil? and node[:ec2][:instance_type] == 't1.micro' } 8 | creates "/swap.img" 9 | end 10 | 11 | mount '/dev/null' do # swap file entry for fstab (d2) 12 | action :enable # cannot mount; only add to fstab 13 | device '/swap.img' 14 | fstype 'swap' 15 | only_if { not node[:ec2].nil? and node[:ec2][:instance_type] == 't1.micro' } 16 | end 17 | 18 | bash 'activate swap' do (d3) 19 | code 'swapon -ae' 20 | only_if "test `cat /proc/swaps | wc -l` -eq 1" 21 | end 22 | -------------------------------------------------------------------------------- /chapter03/list3-32.txt: -------------------------------------------------------------------------------- 1 | git "/home/vagrant/.oh-my-zsh" do 2 | repository "git://github.com/robbyrussell/oh-my-zsh.git" 3 | reference "master" 4 | action :checkout 5 | user "vagrant" 6 | group "vagrant" 7 | end 8 | -------------------------------------------------------------------------------- /chapter03/list3-33.txt: -------------------------------------------------------------------------------- 1 | gem_package "rake" do 2 | action :install 3 | end 4 | -------------------------------------------------------------------------------- /chapter03/list3-34.txt: -------------------------------------------------------------------------------- 1 | gem_package 'fluent-plugin-extract_query_params' do 2 | gem_binary "/usr/lib64/fluent/ruby/bin/fluent-gem" 3 | version '0.0.2' 4 | action :upgrade 5 | end 6 | -------------------------------------------------------------------------------- /chapter03/list3-35.txt: -------------------------------------------------------------------------------- 1 | cron "name_of_cron_entry" do 2 | hour 8 3 | weekday 6 4 | mailto admin@example.com 5 | action :create 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-36.txt: -------------------------------------------------------------------------------- 1 | file "/path/to/something" do 2 | owner "root" 3 | group "root" 4 | mode 00755 5 | action :create 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-37.txt: -------------------------------------------------------------------------------- 1 | file "/path/to/something" do 2 | content "Chef Practical Guide Sample" 3 | owner "root" 4 | group "root" 5 | mode 00755 6 | action :create 7 | end 8 | -------------------------------------------------------------------------------- /chapter03/list3-38.txt: -------------------------------------------------------------------------------- 1 | http_request "please_delete_me" do 2 | url "http://www.example.com/some_page" 3 | action :get 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-39.txt: -------------------------------------------------------------------------------- 1 | link "/tmp/passwd" do 2 | to "/etc/passwd" 3 | link_type :hard 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-40.txt: -------------------------------------------------------------------------------- 1 | route "10.0.1.10/32" do 2 | gateway "10.0.0.20" 3 | device "eth1" 4 | end 5 | -------------------------------------------------------------------------------- /chapter03/list3-41.txt: -------------------------------------------------------------------------------- 1 | ruby_block "reload_client_config" do 2 | block do 3 | Chef::Config.from_file("/etc/chef/client.rb") 4 | end 5 | action :create 6 | end 7 | -------------------------------------------------------------------------------- /chapter03/list3-42.txt: -------------------------------------------------------------------------------- 1 | { 2 | "httpd" : { 3 | "port" : 80 4 | }, 5 | "run_list":[ 6 | "recipe[git]", 7 | "recipe[apache]", 8 | "recipe[mysql]" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /chapter03/list3-43.txt: -------------------------------------------------------------------------------- 1 | default["apache"]["dir"] = "/etc/apache2" 2 | default["apache"]["listen_ports"] = [ "80", "443" ] 3 | -------------------------------------------------------------------------------- /chapter03/list3-44.txt: -------------------------------------------------------------------------------- 1 | { 2 | "id" : "naoya", 3 | "username" : "naoya", 4 | "home" : "/home/naoya", 5 | "shell" : "/bin/bash" 6 | } 7 | -------------------------------------------------------------------------------- /chapter03/list3-45.txt: -------------------------------------------------------------------------------- 1 | { 2 | "id" : "inao", 3 | "username" : "inao", 4 | "home" : "/home/inao", 5 | "shell" : "/bin/inao" 6 | } 7 | -------------------------------------------------------------------------------- /chapter03/list3-46.txt: -------------------------------------------------------------------------------- 1 | # login_users/recipes/default.rb 2 | data_ids = data_bag('users') 3 | 4 | data_ids.each do |id| 5 | u = data_bag_item('users', id) 6 | user u['username'] do 7 | home u['home'] 8 | shell u['shell'] 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /chapter04/fig4-01.txt: -------------------------------------------------------------------------------- 1 | $ knife cookbook site search apache2 2 | apache2: 3 | cookbook: http://cookbooks.opscode.com/api/v1/cookbooks/apache2 4 | cookbook_description: Installs and configures all aspects of apache2 using Debian style symlinks with helper definitions 5 | cookbook_maintainer: opscode 6 | cookbook_name: apache2 7 | apache2-windows: 8 | cookbook: http://cookbooks.opscode.com/api/v1/cookbooks/apache2-windows 9 | cookbook_description: Installs/configures Apache2 on Windows Azure 10 | cookbook_maintainer: dlrobinson 11 | cookbook_name: apache2-windows 12 | 略 13 | -------------------------------------------------------------------------------- /chapter04/fig4-02.txt: -------------------------------------------------------------------------------- 1 | $ knife cookbook site show apache2 | head -20 2 | average_rating: 4.75 3 | category: Web Servers 4 | created_at: 2009-10-25T23:47:55Z 5 | description: Installs and configures all aspects of apache2 using Debian style symlinks with helper definitions 6 | external_url: github.com/opscode-cookbooks/apache2 7 | latest_version: http://cookbooks.opscode.com/api/v1/cookbooks/apache2/versions/1_9_6 8 | maintainer: opscode 9 | name: apache2 10 | updated_at: 2014-02-28T16:33:09Z 11 | versions: 12 | http://cookbooks.opscode.com/api/v1/cookbooks/apache2/versions/1_9_6 13 | http://cookbooks.opscode.com/api/v1/cookbooks/apache2/versions/1_9_4 14 | -------------------------------------------------------------------------------- /chapter04/fig4-03.txt: -------------------------------------------------------------------------------- 1 | $ berks 2 | Using yum-epel (0.2.0) 3 | Using apache2 (1.8.14) 4 | Using mysql (4.0.20) 5 | Using yum (3.0.4) 6 | Using openssl (1.1.0) 7 | Using build-essential (1.4.2) 8 | -------------------------------------------------------------------------------- /chapter04/fig4-05.txt: -------------------------------------------------------------------------------- 1 | $ vagrant up 2 | Bringing machine 'node01' up with 'virtualbox' provider... 3 | Bringing machine 'node02' up with 'virtualbox' provider... 4 | ==> node01: Importing base box 'opscode-centos-6.5'... 5 | Progress: 60% 6 | -------------------------------------------------------------------------------- /chapter04/fig4-06.txt: -------------------------------------------------------------------------------- 1 | $ vagrant ssh node01 2 | $ vagrant ssh-config node01 >> ~/.ssh/config 3 | $ vagrant halt node01 4 | $ vagrant destroy node01 5 | $ vagrant up node01 6 | -------------------------------------------------------------------------------- /chapter04/list4-01.txt: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook 'yum-epel' 4 | cookbook 'apache2' 5 | cookbook 'mysql' 6 | -------------------------------------------------------------------------------- /chapter04/list4-02.txt: -------------------------------------------------------------------------------- 1 | { 2 | "sources": { 3 | "yum-epel": { 4 | "locked_version": "0.2.0" 5 | }, 6 | "apache2": { 7 | "locked_version": "1.8.14" 8 | }, 9 | "mysql": { 10 | 略 11 | -------------------------------------------------------------------------------- /chapter04/list4-03.txt: -------------------------------------------------------------------------------- 1 | { 2 | "run_list":[ 3 | "recipe[yum-epel]", 4 | 略 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /chapter04/list4-04.txt: -------------------------------------------------------------------------------- 1 | cookbook_path ["cookbooks", "site-cookbooks"] 2 | node_path "nodes" 3 | role_path "roles" 4 | environment_path "environments" 5 | data_bag_path "data_bags" 6 | #encrypted_data_bag_secret "data_bag_key" 7 | 8 | knife[:berkshelf_path] = "cookbooks" 9 | -------------------------------------------------------------------------------- /chapter04/list4-05.txt: -------------------------------------------------------------------------------- 1 | { 2 | "run_list":[ 3 | "recipe[apache2]" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /chapter04/list4-06.txt: -------------------------------------------------------------------------------- 1 | default['apache']['root_group'] = 'root' 2 | 3 | # Where the various parts of apache are 4 | case node['platform'] 5 | when 'redhat', 'centos', 'scientific', 'fedora', 'suse', 'amazon', 'oracle' 6 | default['apache']['package'] = 'httpd' 7 | default['apache']['dir'] = '/etc/httpd' 8 | default['apache']['log_dir'] = '/var/log/httpd' 9 | default['apache']['error_log'] = 'error.log' 10 | 略 11 | -------------------------------------------------------------------------------- /chapter04/list4-07.txt: -------------------------------------------------------------------------------- 1 | { 2 | "apache": { 3 | "listen_ports": [ 8080 ], 4 | "keepalive": "Off", 5 | "docroot_dir": "/home/vagrant/htdocs" 6 | }, 7 | "run_list":[ 8 | "recipe[apache2]" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /chapter04/list4-08.txt: -------------------------------------------------------------------------------- 1 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 2 | config.vm.box = "opscode-centos-6.5" 3 | 略 4 | 5 | # 次の2行を追加 6 | config.vm.define :node01 7 | config.vm.define :node02 8 | end 9 | -------------------------------------------------------------------------------- /chapter04/list4-09.txt: -------------------------------------------------------------------------------- 1 | config.vm.define :node01 do |node01| 2 | node01.vm.box = "opscode-ubuntu-12.04" 3 | end 4 | -------------------------------------------------------------------------------- /chapter04/list4-10.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web", 3 | "chef_type": "role", 4 | "json_class": "Chef::Role", 5 | "run_list": [ 6 | "recipe[git]", 7 | "recipe[apache2]" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /chapter04/list4-11.txt: -------------------------------------------------------------------------------- 1 | { 2 | "run_list":[ 3 | "role[web]" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /chapter04/list4-12.txt: -------------------------------------------------------------------------------- 1 | { 2 | "run_list":[ 3 | "recipe[git]", 4 | "role[web]", 5 | "role[db]" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /chapter04/list4-13.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web", 3 | "chef_type": "role", 4 | "json_class": "Chef::Role", 5 | "default_attributes": { 6 | "apache": { 7 | "listen_ports": [ 8 | "80", 9 | "443" 10 | ] 11 | } 12 | }, 13 | "override_attributes": { 14 | "apache": { 15 | "max_children" : "50" 16 | } 17 | }, 18 | "run_list": [ 19 | "recipe[git]", 20 | "recipe[apache2]" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /chapter04/list4-14.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "development", 3 | "description":"Development environment", 4 | "chef_type": "environment", 5 | "json_class": "Chef::Environment", 6 | "default_attributes": { 7 | "apache": { 8 | "max_children": "10" 9 | } 10 | }, 11 | "override_attributes": {} 12 | } 13 | -------------------------------------------------------------------------------- /chapter04/list4-15.txt: -------------------------------------------------------------------------------- 1 | { 2 | "environment": "development", 3 | "run_list":[ 4 | "role[web]" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /chapter05/list5.1/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | 8 | config.vm.box = "opscode-centos-6.5" 9 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 10 | # Chef Clientの最新版を利用可能にする 11 | config.omnibus.chef_version = :latest 12 | 13 | config.vm.provision :chef_solo do |chef| 14 | # (d1)クックブックの配置場所を指定 15 | chef.cookbooks_path = "./cookbooks" 16 | # (d2)Attributeの定義 17 | chef.json = { 18 | nginx: { 19 | env: "ruby" 20 | }, 21 | fluentd: { 22 | installer: "rpm" 23 | }, 24 | mysql: { 25 | server_root_password: 'rootpass' 26 | } 27 | } 28 | # (d3)適用するクックブックの定義 29 | chef.run_list = %w[ 30 | recipe[yum-epel] 31 | recipe[nginx] 32 | recipe[mysql] 33 | recipe[fluentd] 34 | ] 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /chapter05/list5.3/base.sh: -------------------------------------------------------------------------------- 1 | /usr/sbin/setenforce 0 2 | sudo sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers 3 | sudo sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config 4 | 5 | cat <> /etc/sudoers.d/vagrant 35 | chmod 0440 /etc/sudoers.d/vagrant 36 | %end 37 | 38 | -------------------------------------------------------------------------------- /chapter05/list5.3/template.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders":[{ 3 | "type": "virtualbox-iso", 4 | "guest_os_type": "RedHat_64", 5 | "iso_url": "http://ftp.iij.ad.jp/pub/linux/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso", 6 | "iso_checksum": "0d9dc37b5dd4befa1c440d2174e88a87", 7 | "iso_checksum_type": "md5", 8 | "ssh_username": "vagrant", 9 | "ssh_password": "vagrant", 10 | "ssh_wait_timeout": "3000s", 11 | "vm_name": "box", 12 | "http_directory": "./", 13 | "boot_wait": "30s", 14 | "boot_command":[ 15 | "", 16 | "linux ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg ", 17 | "" 18 | ], 19 | "shutdown_command": "sudo /sbin/poweroff" 20 | }], 21 | "provisioners":[{ 22 | "type": "shell", 23 | "scripts": [ 24 | "base.sh" 25 | ] 26 | }], 27 | "post-processors": [ 28 | { 29 | "type": "vagrant", 30 | "output": "./CentOS-6.5-x86_64-ja.box" 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /chapter05/list5.7/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | VAGRANTFILE_API_VERSION = "2" 4 | 5 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 6 | 7 | ssh_username = "ec2-user" 8 | region = "ap-northeast-1" 9 | ami = "ami-b1fe9bb0" 10 | instance_type = "t1.micro" 11 | 12 | config.vm.box = "dummy" 13 | config.vm.provider :aws do |aws, override| 14 | aws.access_key_id = ENV['AWS_ACCESS_KEY_ID'] 15 | aws.secret_access_key = ENV['AWS_SECRET_KEY'] 16 | aws.keypair_name = ENV['AWS_KEYPAIR_NAME'] 17 | override.ssh.username = ssh_username 18 | override.ssh.private_key_path = ENV['AWS_PRIVATE_KEY_PATH'] 19 | 20 | aws.region = region 21 | aws.elastic_ip = true 22 | aws.security_groups = ["chef_practical_guide"] 23 | # User-data 24 | aws.user_data = "#!/bin/sh\nsed -i 's/^.*requiretty/#Defaults requiretty/' /etc/sudoers\n" 25 | # タグを指定(任意) 26 | aws.tags = aws.tags = { "Name" => "test-minimal", "env" => "dev"} 27 | # AMIを指定。起動したいリージョンにあるAMI 28 | aws.ami = ami 29 | # インスタンスタイプを設定 30 | aws.instance_type = instance_type 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /chapter06/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | cookbook "php-env", path: "./site-cookbooks/php-env" 6 | cookbook "ruby-env", path: "./site-cookbooks/ruby-env" 7 | cookbook "nodejs", path: "./site-cookbooks/nodejs" 8 | cookbook "mysql", path: "./site-cookbooks/mysql" 9 | cookbook "fluentd", path: "./site-cookbooks/fluentd" 10 | -------------------------------------------------------------------------------- /chapter06/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'chef' 4 | gem 'knife-solo' 5 | gem 'berkshelf', "2.0.16" 6 | -------------------------------------------------------------------------------- /chapter06/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php", "ruby"] 20 | }, 21 | mysql: { 22 | server_root_password: 'rootpass' 23 | }, 24 | fluentd: { 25 | installer: "rpm" 26 | } 27 | } 28 | chef.run_list = %w[ 29 | recipe[yum] 30 | recipe[yum-epel] 31 | recipe[nginx] 32 | recipe[php-env::php55] 33 | recipe[ruby-env] 34 | recipe[nodejs] 35 | recipe[mysql] 36 | recipe[fluentd] 37 | ] 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /chapter06/Vagrantfile.dbmaster: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | config.vm.define "dbmaster" do |dbmaster| 11 | dbmaster.vm.hostname = "dbmaster" 12 | dbmaster.vm.network :private_network, ip: "192.168.33.10" 13 | end 14 | 15 | config.vm.define "dbslave" do |dbslave| 16 | dbslave.vm.hostname = "dbslave" 17 | dbslave.vm.network :private_network, ip: "192.168.33.11" 18 | end 19 | 20 | # vagrant-omnibusの有効化 21 | config.omnibus.chef_version = :latest 22 | config.vm.provision :chef_solo do |chef| 23 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 24 | chef.json = { 25 | nginx: { 26 | env: ["php", "ruby"] 27 | }, 28 | mysql: { 29 | server_root_password: 'rootpass' 30 | } 31 | } 32 | chef.run_list = %w[ 33 | recipe[yum] 34 | recipe[yum-epel] 35 | recipe[nginx] 36 | recipe[php-env::php55] 37 | recipe[ruby-env] 38 | recipe[nodejs] 39 | recipe[mysql] 40 | ] 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /chapter06/list6.1/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'chef' 4 | gem 'knife-solo' 5 | gem 'berkshelf', "2.0.16" 6 | -------------------------------------------------------------------------------- /chapter06/list6.10/default.rb: -------------------------------------------------------------------------------- 1 | include_recipe "yum-epel" 2 | 3 | package "nginx" do 4 | action :install 5 | end 6 | 7 | service "nginx" do 8 | action [ :enable, :start ] 9 | supports :status => true, :restart => true, :reload => true 10 | end 11 | 12 | template 'nginx.conf' do 13 | path '/etc/nginx/nginx.conf' 14 | source "nginx.conf.erb" 15 | owner 'root' 16 | group 'root' 17 | mode '0644' 18 | notifies :reload, "service[nginx]" 19 | end 20 | -------------------------------------------------------------------------------- /chapter06/list6.11/default.rb: -------------------------------------------------------------------------------- 1 | default['nginx']['env'] = [] 2 | -------------------------------------------------------------------------------- /chapter06/list6.12/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php"] 20 | } 21 | } 22 | chef.run_list = %w[ 23 | recipe[yum-epel] 24 | recipe[nginx] 25 | recipe[php-env] 26 | ] 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /chapter06/list6.13/default.rb: -------------------------------------------------------------------------------- 1 | %w{php-fpm php-pecl-zendopcache}.each do |pkg| 2 | package pkg do 3 | action :install 4 | notifies :restart, "service[php-fpm]" 5 | end 6 | end 7 | 8 | service "php-fpm" do 9 | action [:enable, :start] 10 | end 11 | -------------------------------------------------------------------------------- /chapter06/list6.14/index.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /chapter06/list6.15/php55.rb: -------------------------------------------------------------------------------- 1 | yum_repository 'remi' do 2 | description 'Les RPM de Remi - Repository' 3 | baseurl 'http://rpms.famillecollet.com/enterprise/6/remi/x86_64/' 4 | gpgkey 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi' 5 | fastestmirror_enabled true 6 | action :create 7 | end 8 | 9 | yum_repository 'remi-php55' do 10 | description 'Les RPM de remi de PHP 5.5 pour Enterprise Linux 6' 11 | baseurl 'http://rpms.famillecollet.com/enterprise/6/php55/$basearch/' 12 | gpgkey 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi' 13 | fastestmirror_enabled true 14 | action :create 15 | end 16 | 17 | %w{php php-fpm php-opcache}.each do |pkg| 18 | package pkg do 19 | action :install 20 | notifies :restart, "service[php-fpm]" 21 | end 22 | end 23 | 24 | service "php-fpm" do 25 | action [:enable, :start] 26 | end 27 | -------------------------------------------------------------------------------- /chapter06/list6.16/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php"] 20 | } 21 | } 22 | chef.run_list = %w[ 23 | recipe[yum] 24 | recipe[yum-epel] 25 | recipe[nginx] 26 | recipe[php-env::php55] 27 | ] 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /chapter06/list6.18/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | cookbook "php-env", path: "./site-cookbooks/php-env" 6 | cookbook "ruby-env", path: "./site-cookbooks/ruby-env" 7 | -------------------------------------------------------------------------------- /chapter06/list6.19/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php"] 20 | } 21 | } 22 | chef.run_list = %w[ 23 | recipe[yum] 24 | recipe[yum-epel] 25 | recipe[nginx] 26 | recipe[php-env::php55] 27 | recipe[ruby-env] 28 | ] 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /chapter06/list6.2/default.rb: -------------------------------------------------------------------------------- 1 | include_recipe "yum-epel" 2 | 3 | package "nginx" do 4 | action :install 5 | end 6 | 7 | service "nginx" do 8 | action [ :enable, :start ] 9 | supports :status => true, :restart => true, :reload => true 10 | end 11 | 12 | -------------------------------------------------------------------------------- /chapter06/list6.20/default.rb: -------------------------------------------------------------------------------- 1 | %w{gcc git openssl-devel sqlite-devel}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | git "/home/#{node['ruby-env']['user']}/.rbenv" do 8 | repository node["ruby-env"]["rbenv_url"] 9 | action :sync 10 | user node['ruby-env']['user'] 11 | group node['ruby-env']['group'] 12 | end 13 | 14 | template ".bash_profile" do 15 | source ".bash_profile.erb" 16 | path "/home/#{node['ruby-env']['user']}/.bash_profile" 17 | mode 0644 18 | owner node['ruby-env']['user'] 19 | group node['ruby-env']['group'] 20 | not_if "grep rbenv ~/.bash_profile", :environment => { :'HOME' => "/home/#{node['ruby-env']['user']}" } 21 | end 22 | -------------------------------------------------------------------------------- /chapter06/list6.21/default.rb: -------------------------------------------------------------------------------- 1 | default['ruby-env']['user'] = "vagrant" 2 | default['ruby-env']['group'] = "vagrant" 3 | default['ruby-env']['version'] = "2.1.1" 4 | default["ruby-env"]["rbenv_url"] = "https://github.com/sstephenson/rbenv" 5 | default["ruby-env"]["ruby-build_url"] = "https://github.com/sstephenson/ruby-build" 6 | -------------------------------------------------------------------------------- /chapter06/list6.22/.bash_profile.erb: -------------------------------------------------------------------------------- 1 | # .bash_profile 2 | 3 | # Get the aliases and functions 4 | if [ -f ~/.bashrc ]; then 5 | . ~/.bashrc 6 | fi 7 | 8 | # User specific environment and startup programs 9 | PATH=$PATH:$HOME/bin 10 | export PATH="$HOME/.rbenv/bin:$PATH" 11 | eval "$(rbenv init -)" 12 | -------------------------------------------------------------------------------- /chapter06/list6.23/default.rb: -------------------------------------------------------------------------------- 1 | %w{gcc git openssl-devel sqlite-devel}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | git "/home/#{node['ruby-env']['user']}/.rbenv" do 8 | repository node["ruby-env"]["rbenv_url"] 9 | action :sync 10 | user node['ruby-env']['user'] 11 | group node['ruby-env']['group'] 12 | end 13 | 14 | template ".bash_profile" do 15 | source ".bash_profile.erb" 16 | path "/home/#{node['ruby-env']['user']}/.bash_profile" 17 | mode 0644 18 | owner node['ruby-env']['user'] 19 | group node['ruby-env']['group'] 20 | not_if "grep rbenv ~/.bash_profile", :environment => { :'HOME' => "/home/#{node['ruby-env']['user']}" } 21 | end 22 | 23 | directory "/home/#{node['ruby-env']['user']}/.rbenv/plugins" do 24 | owner node['ruby-env']['user'] 25 | group node['ruby-env']['group'] 26 | mode 0755 27 | action :create 28 | end 29 | 30 | git "/home/#{node['ruby-env']['user']}/.rbenv/plugins/ruby-build" do 31 | repository node["ruby-env"]["ruby-build_url"] 32 | action :sync 33 | user node['ruby-env']['user'] 34 | group node['ruby-env']['group'] 35 | end 36 | 37 | execute "rbenv install #{node['ruby-env']['version']}" do 38 | command "/home/#{node['ruby-env']['user']}/.rbenv/bin/rbenv install #{node['ruby-env']['version']}" 39 | user node['ruby-env']['user'] 40 | group node['ruby-env']['group'] 41 | environment 'HOME' => "/home/#{node['ruby-env']['user']}" 42 | not_if { File.exists?("/home/#{node['ruby-env']['user']}/.rbenv/versions/#{node['ruby-env']['version']}")} 43 | end 44 | -------------------------------------------------------------------------------- /chapter06/list6.24/default.rb: -------------------------------------------------------------------------------- 1 | execute "rbenv global #{node['ruby-env']['version']}" do 2 | command "/home/#{node['ruby-env']['user']}/.rbenv/bin/rbenv global #{node['ruby-env']['version']}" 3 | user node['ruby-env']['user'] 4 | group node['ruby-env']['group'] 5 | environment 'HOME' => "/home/#{node['ruby-env']['user']}" 6 | end 7 | 8 | %w{rbenv-rehash bundler}.each do |gem| 9 | execute "gem install #{gem}" do 10 | command "/home/#{node['ruby-env']['user']}/.rbenv/shims/gem install #{gem}" 11 | user node['ruby-env']['user'] 12 | group node['ruby-env']['group'] 13 | environment 'HOME' => "/home/#{node['ruby-env']['user']}" 14 | not_if "/home/#{node['ruby-env']['user']}/.rbenv/shims/gem list | grep #{gem}" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /chapter06/list6.25/nginx.conf.erb: -------------------------------------------------------------------------------- 1 | user nginx; 2 | worker_processes 1; 3 | 4 | error_log /var/log/nginx/error.log warn; 5 | pid /var/run/nginx.pid; 6 | 7 | events { 8 | worker_connections 1024; 9 | } 10 | 11 | http { 12 | include /etc/nginx/mime.types; 13 | default_type application/octet-stream; 14 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 15 | '$status $body_bytes_sent "$http_referer" ' 16 | '"$http_user_agent" "$http_x_forwarded_for"'; 17 | access_log /var/log/nginx/access.log main; 18 | sendfile on; 19 | keepalive_timeout 65; 20 | 21 | <% if node['nginx']['env'].include?("ruby") %> 22 | upstream unicorn { 23 | server unix:/tmp/unicorn.sock; 24 | } 25 | <% end %> 26 | 27 | server { 28 | listen 80 default_server; 29 | server_name _; 30 | 31 | location / { 32 | root /usr/share/nginx/html; 33 | index index.html index.htm index.php; 34 | } 35 | 36 | error_page 404 /404.html; 37 | location = /404.html { 38 | root /usr/share/nginx/html; 39 | } 40 | 41 | # redirect server error pages to the static page /50x.html 42 | # 43 | error_page 500 502 503 504 /50x.html; 44 | location = /50x.html { 45 | root /usr/share/nginx/html; 46 | } 47 | <% if node['nginx']['env'].include?("php") %> 48 | location ~ \.php$ { 49 | fastcgi_pass 127.0.0.1:9000; 50 | fastcgi_index index.php; 51 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 52 | include fastcgi_params; 53 | } 54 | <% end %> 55 | <% if node['nginx']['env'].include?("ruby") %> 56 | location /unicorn { 57 | rewrite ^/unicorn/(.+) /$1 break; 58 | proxy_pass http://unicorn/$1; 59 | } 60 | <% end %> 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /chapter06/list6.26/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php", "ruby"] 20 | } 21 | } 22 | chef.run_list = %w[ 23 | recipe[yum] 24 | recipe[yum-epel] 25 | recipe[nginx] 26 | recipe[php-env::php55] 27 | recipe[ruby-env] 28 | ] 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /chapter06/list6.27/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '4.0.4' 4 | gem 'sqlite3' 5 | gem 'sass-rails', '~> 4.0.2' 6 | gem 'uglifier', '>= 1.3.0' 7 | gem 'coffee-rails', '~> 4.0.0' 8 | gem 'jquery-rails' 9 | gem 'turbolinks' 10 | gem 'jbuilder', '~> 1.2' 11 | 12 | group :doc do 13 | gem 'sdoc', require: false 14 | end 15 | 16 | gem 'unicorn' 17 | -------------------------------------------------------------------------------- /chapter06/list6.28/unicorn.rb: -------------------------------------------------------------------------------- 1 | listen "/tmp/unicorn.sock" 2 | worker_processes 2 # this should be >= nr_cpus 3 | pid "/home/vagrant/test_unicorn/shared/pids/unicorn.pid" 4 | stderr_path "/home/vagrant/test_unicorn/shared/log/unicorn.log" 5 | stdout_path "/home/vagrant/test_unicorn/shared/log/unicorn.log" 6 | -------------------------------------------------------------------------------- /chapter06/list6.29/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | cookbook "php-env", path: "./site-cookbooks/php-env" 6 | cookbook "ruby-env", path: "./site-cookbooks/ruby-env" 7 | cookbook "nodejs", path: "./site-cookbooks/nodejs" 8 | -------------------------------------------------------------------------------- /chapter06/list6.3/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | -------------------------------------------------------------------------------- /chapter06/list6.30/default.rb: -------------------------------------------------------------------------------- 1 | %w{gcc-c++}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | remote_file "/tmp/#{node['nodejs']['filename']}" do 8 | source "#{node['nodejs']['remote_uri']}" 9 | end 10 | 11 | bash "install nodejs" do 12 | user "root" 13 | cwd "/tmp" 14 | code <<-EOC 15 | tar xvzf #{node['nodejs']['filename']} 16 | cd #{node['nodejs']['dirname']} 17 | make 18 | make install 19 | EOC 20 | end 21 | -------------------------------------------------------------------------------- /chapter06/list6.31/default.rb: -------------------------------------------------------------------------------- 1 | default['nodejs']['version'] = "v0.10.26" 2 | default['nodejs']['dirname'] = "node-#{default['nodejs']['version']}" 3 | default['nodejs']['filename'] = "#{default['nodejs']['dirname']}.tar.gz" 4 | default['nodejs']['remote_uri'] = "http://nodejs.org/dist/#{default['nodejs']['version']}/#{default['nodejs']['filename']}" 5 | -------------------------------------------------------------------------------- /chapter06/list6.32/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php", "ruby"] 20 | } 21 | } 22 | chef.run_list = %w[ 23 | recipe[yum] 24 | recipe[yum-epel] 25 | recipe[nginx] 26 | recipe[php-env::php55] 27 | recipe[ruby-env] 28 | recipe[nodejs] 29 | ] 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /chapter06/list6.33/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | cookbook "php-env", path: "./site-cookbooks/php-env" 6 | cookbook "ruby-env", path: "./site-cookbooks/ruby-env" 7 | cookbook "nodejs", path: "./site-cookbooks/nodejs" 8 | cookbook "mysql", path: "./site-cookbooks/mysql" 9 | -------------------------------------------------------------------------------- /chapter06/list6.34/default.rb: -------------------------------------------------------------------------------- 1 | default['mysql']['user'] = "vagrant" 2 | default['mysql']['group'] = "vagrant" 3 | default['mysql']['server_root_password'] = "" 4 | default['mysql']['slave_ipaddress'] = "192.168.33.11" 5 | -------------------------------------------------------------------------------- /chapter06/list6.35/default.rb: -------------------------------------------------------------------------------- 1 | %w{mysql mysql-server}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | service "mysqld" do 8 | action [:enable, :start] 9 | end 10 | 11 | execute "set root password" do 12 | command "mysqladmin -u root password '#{node['mysql']['server_root_password']}'" 13 | only_if "mysql -u root -e 'show databases;'" 14 | end 15 | -------------------------------------------------------------------------------- /chapter06/list6.36/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php", "ruby"] 20 | }, 21 | mysql: { 22 | server_root_password: 'rootpass' 23 | } 24 | } 25 | chef.run_list = %w[ 26 | recipe[yum] 27 | recipe[yum-epel] 28 | recipe[nginx] 29 | recipe[php-env::php55] 30 | recipe[ruby-env] 31 | recipe[nodejs] 32 | recipe[mysql] 33 | ] 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /chapter06/list6.37/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | config.vm.define "dbmaster" do |dbmaster| 11 | dbmaster.vm.hostname = "dbmaster" 12 | dbmaster.vm.network :private_network, ip: "192.168.33.10" 13 | end 14 | 15 | config.vm.define "dbslave" do |dbslave| 16 | dbslave.vm.hostname = "dbslave" 17 | dbslave.vm.network :private_network, ip: "192.168.33.11" 18 | end 19 | 20 | # vagrant-omnibusの有効化 21 | config.omnibus.chef_version = :latest 22 | config.vm.provision :chef_solo do |chef| 23 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 24 | chef.json = { 25 | nginx: { 26 | env: ["php", "ruby"] 27 | }, 28 | mysql: { 29 | server_root_password: 'rootpass' 30 | } 31 | } 32 | chef.run_list = %w[ 33 | recipe[yum] 34 | recipe[yum-epel] 35 | recipe[nginx] 36 | recipe[php-env::php55] 37 | recipe[ruby-env] 38 | recipe[nodejs] 39 | recipe[mysql] 40 | ] 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /chapter06/list6.38/my.cnf.erb: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | log-bin 3 | <% if node['hostname'] == "dbmaster" %> 4 | server-id=1 5 | <% elsif node['hostname'] == "dbslave" %> 6 | server-id=2 7 | <% end %> 8 | datadir=/var/lib/mysql 9 | socket=/var/lib/mysql/mysql.sock 10 | user=mysql 11 | # Disabling symbolic-links is recommended to prevent assorted security risks 12 | symbolic-links=0 13 | 14 | [mysqld_safe] 15 | log-error=/var/log/mysqld.log 16 | pid-file=/var/run/mysqld/mysqld.pid 17 | -------------------------------------------------------------------------------- /chapter06/list6.39/create_slave_user.sql.erb: -------------------------------------------------------------------------------- 1 | GRANT REPLICATION SLAVE ON *.* TO slave@<%= node['mysql']['slave_ipaddress'] %> IDENTIFIED BY 'dbslave'; 2 | -------------------------------------------------------------------------------- /chapter06/list6.4/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | end 10 | -------------------------------------------------------------------------------- /chapter06/list6.40/default.rb: -------------------------------------------------------------------------------- 1 | %w{mysql mysql-server}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | service "mysqld" do 8 | action [:enable, :start] 9 | end 10 | 11 | execute "set root password" do 12 | command "mysqladmin -u root password '#{node['mysql']['server_root_password']}'" 13 | only_if "mysql -u root -e 'show databases;'" 14 | end 15 | 16 | template "create slave user sql" do 17 | path "/home/#{node['mysql']['user']}/create_slave_user.sql" 18 | source "create_slave_user.sql.erb" 19 | owner node['mysql']['user'] 20 | group node['mysql']['group'] 21 | mode "0644" 22 | end 23 | 24 | execute "exec create_slave_user.sql" do 25 | command "mysql -u root --password='#{node['mysql']['server_root_password']}' < /home/#{node['mysql']['user']}/create_slave_user.sql" 26 | user node['mysql']['user'] 27 | group node['mysql']['group'] 28 | environment 'HOME' => "/home/#{node['mysql']['user']}" 29 | only_if { node['hostname'] == "dbmaster" } 30 | end 31 | 32 | template "my.cnf" do 33 | path "/etc/my.cnf" 34 | source "my.cnf.erb" 35 | owner "root" 36 | group "root" 37 | mode "0644" 38 | notifies :restart, "service[mysqld]" 39 | end 40 | -------------------------------------------------------------------------------- /chapter06/list6.41/daily_slave_backup.sh.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | filename=slave_dumpall_`date '+%Y%m%d%H%M'`.dump.gz 4 | 5 | mysqladmin stop-slave -u root -p"<%= node['mysql']['server_root_password'] %>" 6 | mysqldump --all-databases -u root -p"<%= node['mysql']['server_root_password'] %>" > $filename 7 | mysqladmin start-slave -u root -p"<%= node['mysql']['server_root_password'] %>" 8 | -------------------------------------------------------------------------------- /chapter06/list6.42/default.rb: -------------------------------------------------------------------------------- 1 | %w{mysql mysql-server}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | service "mysqld" do 8 | action [:enable, :start] 9 | end 10 | 11 | execute "set root password" do 12 | command "mysqladmin -u root password '#{node['mysql']['server_root_password']}'" 13 | only_if "mysql -u root -e 'show databases;'" 14 | end 15 | 16 | template "create slave user sql" do 17 | path "/home/#{node['mysql']['user']}/create_slave_user.sql" 18 | source "create_slave_user.sql.erb" 19 | owner node['mysql']['user'] 20 | group node['mysql']['group'] 21 | mode "0644" 22 | end 23 | 24 | execute "exec create_slave_user.sql" do 25 | command "mysql -u root --password='#{node['mysql']['server_root_password']}' < /home/#{node['mysql']['user']}/create_slave_user.sql" 26 | user node['mysql']['user'] 27 | group node['mysql']['group'] 28 | environment 'HOME' => "/home/#{node['mysql']['user']}" 29 | only_if { node['hostname'] == "dbmaster" } 30 | end 31 | 32 | template "my.cnf" do 33 | path "/etc/my.cnf" 34 | source "my.cnf.erb" 35 | owner "root" 36 | group "root" 37 | mode "0644" 38 | notifies :restart, "service[mysqld]" 39 | end 40 | 41 | template "daily_slave_backup.sh" do 42 | path "/home/#{node['mysql']['user']}/daily_slave_backup.sh" 43 | source "daily_slave_backup.sh.erb" 44 | owner node['mysql']['user'] 45 | group node['mysql']['group'] 46 | mode "0700" 47 | only_if { node['hostname'] == "dbslave" } 48 | end 49 | 50 | cron "exec daily_backup" do 51 | command "/home/#{node['mysql']['user']}/daily_slave_backup.sh" 52 | hour "4" 53 | minute "30" 54 | day "*" 55 | user "root" 56 | action :create 57 | only_if { node['hostname'] == "dbslave" } 58 | end 59 | -------------------------------------------------------------------------------- /chapter06/list6.43/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | cookbook "php-env", path: "./site-cookbooks/php-env" 6 | cookbook "ruby-env", path: "./site-cookbooks/ruby-env" 7 | cookbook "nodejs", path: "./site-cookbooks/nodejs" 8 | cookbook "mysql", path: "./site-cookbooks/mysql" 9 | cookbook "fluentd", path: "./site-cookbooks/fluentd" 10 | -------------------------------------------------------------------------------- /chapter06/list6.44/site-cookbooks/fluentd/recipes/default.rb: -------------------------------------------------------------------------------- 1 | if (node['fluentd']['installer'] == "rpm") 2 | # install from rpm(omnibus installer) 3 | execute "install td-agent by using rpm" do 4 | command "curl -L http://toolbelt.treasure-data.com/sh/install-redhat.sh | sh" 5 | end 6 | template "fluent.conf.erb" do 7 | path "/etc/td-agent/td-agent.conf" 8 | source "fluent.conf.erb" 9 | owner "root" 10 | group "root" 11 | mode "0644" 12 | notifies :restart, "service[td-agent]" 13 | end 14 | service "td-agent" do 15 | action [:enable, :start] 16 | end 17 | else 18 | # install from rubygems 19 | execute "gem install fluentd" do 20 | command "/home/#{node['fluentd']['user']}/.rbenv/shims/gem install fluentd --no-ri --no-rdoc" 21 | user node['fluentd']['user'] 22 | group node['fluentd']['group'] 23 | environment 'HOME' => "/home/#{node['fluentd']['user']}" 24 | end 25 | execute "fluentd --setup ./fluent" do 26 | command "/home/#{node['fluentd']['user']}/.rbenv/shims/fluentd --setup /home/#{node['fluentd']['user']}/fluent" 27 | user node['fluentd']['user'] 28 | group node['fluentd']['group'] 29 | environment 'HOME' => "/home/#{node['fluentd']['user']}" 30 | not_if { File.exists?("/home/#{node['fluentd']['user']}/fluent")} 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /chapter06/list6.44/site-cookbooks/fluentd/templates/default/fluent.conf.erb: -------------------------------------------------------------------------------- 1 | 2 | ## built-in TCP input 3 | ## $ echo | fluent-cat 4 | 5 | type forward 6 | 7 | 8 | ## built-in UNIX socket input 9 | # 10 | # type unix 11 | # 12 | 13 | # HTTP input 14 | # http://localhost:8888/?json= 15 | 16 | type http 17 | port 8888 18 | 19 | 20 | ## File input 21 | ## read apache logs with tag=apache.access 22 | # 23 | # type tail 24 | # format apache 25 | # path /var/log/httpd-access.log 26 | # tag apache.access 27 | # 28 | 29 | # Listen HTTP for monitoring 30 | # http://localhost:24220/api/plugins 31 | # http://localhost:24220/api/plugins?type=TYPE 32 | # http://localhost:24220/api/plugins?tag=MYTAG 33 | 34 | type monitor_agent 35 | port 24220 36 | 37 | 38 | # Listen DRb for debug 39 | 40 | type debug_agent 41 | port 24230 42 | 43 | 44 | 45 | ## match tag=apache.access and write to file 46 | # 47 | # type file 48 | # path /var/log/fluent/access 49 | # 50 | 51 | ## match tag=debug.** and dump to console 52 | 53 | type stdout 54 | 55 | 56 | # match tag=system.** and forward to another fluent server 57 | 58 | type forward 59 | host 192.168.0.11 60 | 61 | host 192.168.0.12 62 | 63 | 64 | 65 | ## match tag=myapp.** and forward and write to file 66 | # 67 | # type copy 68 | # 69 | # type forward 70 | # host 192.168.0.13 71 | # buffer_type file 72 | # buffer_path /var/log/fluent/myapp-forward 73 | # retry_limit 50 74 | # flush_interval 10s 75 | # 76 | # 77 | # type file 78 | # path /var/log/fluent/myapp 79 | # 80 | # 81 | 82 | ## match fluent's internal events 83 | # 84 | # type null 85 | # 86 | 87 | ## match not matched logs and write to file 88 | # 89 | # type file 90 | # path /var/log/fluent/else 91 | # compress gz 92 | # 93 | 94 | -------------------------------------------------------------------------------- /chapter06/list6.45/default.rb: -------------------------------------------------------------------------------- 1 | default['fluentd']['installer'] = "gem" 2 | default['fluentd']['user'] = "vagrant" 3 | default['fluentd']['group'] = "vagrant" 4 | -------------------------------------------------------------------------------- /chapter06/list6.46/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.json = { 18 | nginx: { 19 | env: ["php", "ruby"] 20 | }, 21 | mysql: { 22 | server_root_password: 'rootpass' 23 | }, 24 | fluentd: { 25 | installer: "rpm" 26 | } 27 | } 28 | chef.run_list = %w[ 29 | recipe[yum] 30 | recipe[yum-epel] 31 | recipe[nginx] 32 | recipe[php-env::php55] 33 | recipe[ruby-env] 34 | recipe[nodejs] 35 | recipe[mysql] 36 | recipe[fluentd] 37 | ] 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /chapter06/list6.5/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.run_list = %w[ 18 | recipe[yum-epel] 19 | recipe[nginx] 20 | ] 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /chapter06/list6.6/default.rb: -------------------------------------------------------------------------------- 1 | %w{php-fpm}.each do |pkg| 2 | package pkg do 3 | action :install 4 | notifies :restart, "service[php-fpm]" 5 | end 6 | end 7 | 8 | service "php-fpm" do 9 | action [:enable, :start] 10 | end 11 | -------------------------------------------------------------------------------- /chapter06/list6.7/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "opscode-centos-6.5" 8 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" 9 | 10 | # IPアドレスの設定 11 | config.vm.network :private_network, ip: "192.168.33.10" 12 | 13 | # vagrant-omnibusの有効化 14 | config.omnibus.chef_version = :latest 15 | config.vm.provision :chef_solo do |chef| 16 | chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] 17 | chef.run_list = %w[ 18 | recipe[yum-epel] 19 | recipe[nginx] 20 | recipe[php-env] 21 | ] 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /chapter06/list6.8/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | cookbook "yum-epel" 4 | cookbook "nginx", path: "./site-cookbooks/nginx" 5 | cookbook "php-env", path: "./site-cookbooks/php-env" 6 | -------------------------------------------------------------------------------- /chapter06/list6.9/nginx.conf.erb: -------------------------------------------------------------------------------- 1 | user nginx; 2 | worker_processes 1; 3 | 4 | error_log /var/log/nginx/error.log warn; 5 | pid /var/run/nginx.pid; 6 | 7 | events { 8 | worker_connections 1024; 9 | } 10 | 11 | http { 12 | include /etc/nginx/mime.types; 13 | default_type application/octet-stream; 14 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 15 | '$status $body_bytes_sent "$http_referer" ' 16 | '"$http_user_agent" "$http_x_forwarded_for"'; 17 | access_log /var/log/nginx/access.log main; 18 | sendfile on; 19 | keepalive_timeout 65; 20 | 21 | server { 22 | listen 80 default_server; 23 | server_name _; 24 | 25 | location / { 26 | root /usr/share/nginx/html; 27 | index index.html index.htm index.php; 28 | } 29 | 30 | error_page 404 /404.html; 31 | location = /404.html { 32 | root /usr/share/nginx/html; 33 | } 34 | 35 | # redirect server error pages to the static page /50x.html 36 | # 37 | error_page 500 502 503 504 /50x.html; 38 | location = /50x.html { 39 | root /usr/share/nginx/html; 40 | } 41 | <% if node['nginx']['env'].include?("php") %> 42 | location ~ \.php$ { 43 | fastcgi_pass 127.0.0.1:9000; 44 | fastcgi_index index.php; 45 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 46 | include fastcgi_params; 47 | } 48 | <% end %> 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/fluentd/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | fluentd CHANGELOG 2 | ================= 3 | 4 | This file is used to list changes made in each version of the fluentd cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of fluentd 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/fluentd/README.md: -------------------------------------------------------------------------------- 1 | fluentd Cookbook 2 | ================ 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - fluentd needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List your cookbook attributes here. 19 | 20 | e.g. 21 | #### fluentd::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['fluentd']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### fluentd::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `fluentd` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[fluentd]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write your change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/fluentd/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['fluentd']['installer'] = "gem" 2 | default['fluentd']['user'] = "vagrant" 3 | default['fluentd']['group'] = "vagrant" 4 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/fluentd/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'fluentd' 2 | maintainer 'YOUR_COMPANY_NAME' 3 | maintainer_email 'YOUR_EMAIL' 4 | license 'All rights reserved' 5 | description 'Installs/Configures fluentd' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/fluentd/recipes/default.rb: -------------------------------------------------------------------------------- 1 | if (node['fluentd']['installer'] == "rpm") 2 | # install from rpm(omnibus installer) 3 | execute "install td-agent by using rpm" do 4 | command "curl -L http://toolbelt.treasure-data.com/sh/install-redhat.sh | sh" 5 | end 6 | template "fluent.conf.erb" do 7 | path "/etc/td-agent/td-agent.conf" 8 | source "fluent.conf.erb" 9 | owner "root" 10 | group "root" 11 | mode "0644" 12 | notifies :restart, "service[td-agent]" 13 | end 14 | service "td-agent" do 15 | action [:enable, :start] 16 | end 17 | else 18 | # install from rubygems 19 | execute "gem install fluentd" do 20 | command "/home/#{node['fluentd']['user']}/.rbenv/shims/gem install fluentd --no-ri --no-rdoc" 21 | user node['fluentd']['user'] 22 | group node['fluentd']['group'] 23 | environment 'HOME' => "/home/#{node['fluentd']['user']}" 24 | end 25 | execute "fluentd --setup ./fluent" do 26 | command "/home/#{node['fluentd']['user']}/.rbenv/shims/fluentd --setup /home/#{node['fluentd']['user']}/fluent" 27 | user node['fluentd']['user'] 28 | group node['fluentd']['group'] 29 | environment 'HOME' => "/home/#{node['fluentd']['user']}" 30 | not_if { File.exists?("/home/#{node['fluentd']['user']}/fluent")} 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/fluentd/templates/default/fluent.conf.erb: -------------------------------------------------------------------------------- 1 | 2 | ## built-in TCP input 3 | ## $ echo | fluent-cat 4 | 5 | type forward 6 | 7 | 8 | ## built-in UNIX socket input 9 | # 10 | # type unix 11 | # 12 | 13 | # HTTP input 14 | # http://localhost:8888/?json= 15 | 16 | type http 17 | port 8888 18 | 19 | 20 | ## File input 21 | ## read apache logs with tag=apache.access 22 | # 23 | # type tail 24 | # format apache 25 | # path /var/log/httpd-access.log 26 | # tag apache.access 27 | # 28 | 29 | # Listen HTTP for monitoring 30 | # http://localhost:24220/api/plugins 31 | # http://localhost:24220/api/plugins?type=TYPE 32 | # http://localhost:24220/api/plugins?tag=MYTAG 33 | 34 | type monitor_agent 35 | port 24220 36 | 37 | 38 | # Listen DRb for debug 39 | 40 | type debug_agent 41 | port 24230 42 | 43 | 44 | 45 | ## match tag=apache.access and write to file 46 | # 47 | # type file 48 | # path /var/log/fluent/access 49 | # 50 | 51 | ## match tag=debug.** and dump to console 52 | 53 | type stdout 54 | 55 | 56 | # match tag=system.** and forward to another fluent server 57 | 58 | type forward 59 | host 192.168.0.11 60 | 61 | host 192.168.0.12 62 | 63 | 64 | 65 | ## match tag=myapp.** and forward and write to file 66 | # 67 | # type copy 68 | # 69 | # type forward 70 | # host 192.168.0.13 71 | # buffer_type file 72 | # buffer_path /var/log/fluent/myapp-forward 73 | # retry_limit 50 74 | # flush_interval 10s 75 | # 76 | # 77 | # type file 78 | # path /var/log/fluent/myapp 79 | # 80 | # 81 | 82 | ## match fluent's internal events 83 | # 84 | # type null 85 | # 86 | 87 | ## match not matched logs and write to file 88 | # 89 | # type file 90 | # path /var/log/fluent/else 91 | # compress gz 92 | # 93 | 94 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | mysql CHANGELOG 2 | =============== 3 | 4 | This file is used to list changes made in each version of the mysql cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of mysql 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/README.md: -------------------------------------------------------------------------------- 1 | mysql Cookbook 2 | ============== 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - mysql needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List your cookbook attributes here. 19 | 20 | e.g. 21 | #### mysql::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['mysql']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### mysql::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `mysql` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[mysql]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write your change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['mysql']['user'] = "vagrant" 2 | default['mysql']['group'] = "vagrant" 3 | default['mysql']['server_root_password'] = "" 4 | default['mysql']['slave_ipaddress'] = "192.168.33.11" 5 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'mysql' 2 | maintainer 'YOUR_COMPANY_NAME' 3 | maintainer_email 'YOUR_EMAIL' 4 | license 'All rights reserved' 5 | description 'Installs/Configures mysql' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/recipes/default.rb: -------------------------------------------------------------------------------- 1 | %w{mysql mysql-server}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | service "mysqld" do 8 | action [:enable, :start] 9 | end 10 | 11 | execute "set root password" do 12 | command "mysqladmin -u root password '#{node['mysql']['server_root_password']}'" 13 | only_if "mysql -u root -e 'show databases;'" 14 | end 15 | 16 | template "create slave user sql" do 17 | path "/home/#{node['mysql']['user']}/create_slave_user.sql" 18 | source "create_slave_user.sql.erb" 19 | owner node['mysql']['user'] 20 | group node['mysql']['group'] 21 | mode "0644" 22 | end 23 | 24 | execute "exec create_slave_user.sql" do 25 | command "mysql -u root --password='#{node['mysql']['server_root_password']}' < /home/#{node['mysql']['user']}/create_slave_user.sql" 26 | user node['mysql']['user'] 27 | group node['mysql']['group'] 28 | environment 'HOME' => "/home/#{node['mysql']['user']}" 29 | only_if { node['hostname'] == "dbmaster" } 30 | end 31 | 32 | template "my.cnf" do 33 | path "/etc/my.cnf" 34 | source "my.cnf.erb" 35 | owner "root" 36 | group "root" 37 | mode "0644" 38 | notifies :restart, "service[mysqld]" 39 | end 40 | 41 | template "daily_slave_backup.sh" do 42 | path "/home/#{node['mysql']['user']}/daily_slave_backup.sh" 43 | source "daily_slave_backup.sh.erb" 44 | owner node['mysql']['user'] 45 | group node['mysql']['group'] 46 | mode "0700" 47 | only_if { node['hostname'] == "dbslave" } 48 | end 49 | 50 | cron "exec daily_backup" do 51 | command "/home/#{node['mysql']['user']}/daily_slave_backup.sh" 52 | hour "4" 53 | minute "30" 54 | day "*" 55 | user "root" 56 | action :create 57 | only_if { node['hostname'] == "dbslave" } 58 | end 59 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/templates/default/create_slave_user.sql.erb: -------------------------------------------------------------------------------- 1 | GRANT REPLICATION SLAVE ON *.* TO slave@<%= node['mysql']['slave_ipaddress'] %> IDENTIFIED BY 'dbslave'; 2 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/templates/default/daily_slave_backup.sh.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | filename=slave_dumpall_`date '+%Y%m%d%H%M'`.dump.gz 4 | 5 | mysqladmin stop-slave -u root -p"<%= node['mysql']['server_root_password'] %>" 6 | mysqldump --all-databases -u root -p"<%= node['mysql']['server_root_password'] %>" > $filename 7 | mysqladmin start-slave -u root -p"<%= node['mysql']['server_root_password'] %>" 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/mysql/templates/default/my.cnf.erb: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | log-bin 3 | <% if node['hostname'] == "dbmaster" %> 4 | server-id=1 5 | <% elsif node['hostname'] == "dbslave" %> 6 | server-id=2 7 | <% end %> 8 | datadir=/var/lib/mysql 9 | socket=/var/lib/mysql/mysql.sock 10 | user=mysql 11 | # Disabling symbolic-links is recommended to prevent assorted security risks 12 | symbolic-links=0 13 | 14 | [mysqld_safe] 15 | log-error=/var/log/mysqld.log 16 | pid-file=/var/run/mysqld/mysqld.pid 17 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nginx/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | nginx CHANGELOG 2 | =============== 3 | 4 | This file is used to list changes made in each version of the nginx cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of nginx 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nginx/README.md: -------------------------------------------------------------------------------- 1 | nginx Cookbook 2 | ============== 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - nginx needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List your cookbook attributes here. 19 | 20 | e.g. 21 | #### nginx::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['nginx']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### nginx::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `nginx` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[nginx]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write your change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nginx/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['nginx']['env'] = [] 2 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nginx/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'nginx' 2 | maintainer 'YOUR_COMPANY_NAME' 3 | maintainer_email 'YOUR_EMAIL' 4 | license 'All rights reserved' 5 | description 'Installs/Configures nginx' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nginx/recipes/default.rb: -------------------------------------------------------------------------------- 1 | include_recipe "yum-epel" 2 | 3 | package "nginx" do 4 | action :install 5 | end 6 | 7 | service "nginx" do 8 | action [ :enable, :start ] 9 | supports :status => true, :restart => true, :reload => true 10 | end 11 | 12 | template 'nginx.conf' do 13 | path '/etc/nginx/nginx.conf' 14 | source "nginx.conf.erb" 15 | owner 'root' 16 | group 'root' 17 | mode '0644' 18 | notifies :reload, "service[nginx]" 19 | end 20 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nginx/templates/default/nginx.conf.erb: -------------------------------------------------------------------------------- 1 | user nginx; 2 | worker_processes 1; 3 | 4 | error_log /var/log/nginx/error.log warn; 5 | pid /var/run/nginx.pid; 6 | 7 | events { 8 | worker_connections 1024; 9 | } 10 | 11 | http { 12 | include /etc/nginx/mime.types; 13 | default_type application/octet-stream; 14 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 15 | '$status $body_bytes_sent "$http_referer" ' 16 | '"$http_user_agent" "$http_x_forwarded_for"'; 17 | access_log /var/log/nginx/access.log main; 18 | sendfile on; 19 | keepalive_timeout 65; 20 | 21 | <% if node['nginx']['env'].include?("ruby") %> 22 | upstream unicorn { 23 | server unix:/tmp/unicorn.sock; 24 | } 25 | <% end %> 26 | 27 | server { 28 | listen 80 default_server; 29 | server_name _; 30 | 31 | location / { 32 | root /usr/share/nginx/html; 33 | index index.html index.htm index.php; 34 | } 35 | 36 | error_page 404 /404.html; 37 | location = /404.html { 38 | root /usr/share/nginx/html; 39 | } 40 | 41 | # redirect server error pages to the static page /50x.html 42 | # 43 | error_page 500 502 503 504 /50x.html; 44 | location = /50x.html { 45 | root /usr/share/nginx/html; 46 | } 47 | <% if node['nginx']['env'].include?("php") %> 48 | location ~ \.php$ { 49 | fastcgi_pass 127.0.0.1:9000; 50 | fastcgi_index index.php; 51 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 52 | include fastcgi_params; 53 | } 54 | <% end %> 55 | <% if node['nginx']['env'].include?("ruby") %> 56 | location /unicorn { 57 | rewrite ^/unicorn/(.+) /$1 break; 58 | proxy_pass http://unicorn/$1; 59 | } 60 | <% end %> 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nodejs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | nodejs CHANGELOG 2 | ================ 3 | 4 | This file is used to list changes made in each version of the nodejs cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of nodejs 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nodejs/README.md: -------------------------------------------------------------------------------- 1 | nodejs Cookbook 2 | =============== 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - nodejs needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List your cookbook attributes here. 19 | 20 | e.g. 21 | #### nodejs::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['nodejs']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### nodejs::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `nodejs` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[nodejs]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write your change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nodejs/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['nodejs']['version'] = "v0.10.26" 2 | default['nodejs']['dirname'] = "node-#{default['nodejs']['version']}" 3 | default['nodejs']['filename'] = "#{default['nodejs']['dirname']}.tar.gz" 4 | default['nodejs']['remote_uri'] = "http://nodejs.org/dist/#{default['nodejs']['version']}/#{default['nodejs']['filename']}" 5 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nodejs/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'nodejs' 2 | maintainer 'YOUR_COMPANY_NAME' 3 | maintainer_email 'YOUR_EMAIL' 4 | license 'All rights reserved' 5 | description 'Installs/Configures nodejs' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/nodejs/recipes/default.rb: -------------------------------------------------------------------------------- 1 | %w{gcc-c++}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | remote_file "/tmp/#{node['nodejs']['filename']}" do 8 | source "#{node['nodejs']['remote_uri']}" 9 | end 10 | 11 | bash "install nodejs" do 12 | user "root" 13 | cwd "/tmp" 14 | code <<-EOC 15 | tar xvzf #{node['nodejs']['filename']} 16 | cd #{node['nodejs']['dirname']} 17 | make 18 | make install 19 | EOC 20 | end 21 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/php-env/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | php-env CHANGELOG 2 | ================= 3 | 4 | This file is used to list changes made in each version of the php-env cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of php-env 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/php-env/README.md: -------------------------------------------------------------------------------- 1 | php-env Cookbook 2 | ================ 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - php-env needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List your cookbook attributes here. 19 | 20 | e.g. 21 | #### php-env::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['php-env']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### php-env::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `php-env` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[php-env]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write your change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/php-env/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'php-env' 2 | maintainer 'YOUR_COMPANY_NAME' 3 | maintainer_email 'YOUR_EMAIL' 4 | license 'All rights reserved' 5 | description 'Installs/Configures php-env' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/php-env/recipes/default.rb: -------------------------------------------------------------------------------- 1 | %w{php-fpm php-pecl-zendopcache}.each do |pkg| 2 | package pkg do 3 | action :install 4 | notifies :restart, "service[php-fpm]" 5 | end 6 | end 7 | 8 | service "php-fpm" do 9 | action [:enable, :start] 10 | end 11 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/php-env/recipes/php55.rb: -------------------------------------------------------------------------------- 1 | yum_repository 'remi' do 2 | description 'Les RPM de Remi - Repository' 3 | baseurl 'http://rpms.famillecollet.com/enterprise/6/remi/x86_64/' 4 | gpgkey 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi' 5 | fastestmirror_enabled true 6 | action :create 7 | end 8 | 9 | yum_repository 'remi-php55' do 10 | description 'Les RPM de remi de PHP 5.5 pour Enterprise Linux 6' 11 | baseurl 'http://rpms.famillecollet.com/enterprise/6/php55/$basearch/' 12 | gpgkey 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi' 13 | fastestmirror_enabled true 14 | action :create 15 | end 16 | 17 | %w{php php-fpm php-opcache}.each do |pkg| 18 | package pkg do 19 | action :install 20 | notifies :restart, "service[php-fpm]" 21 | end 22 | end 23 | 24 | service "php-fpm" do 25 | action [:enable, :start] 26 | end 27 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/ruby-env/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ruby-env CHANGELOG 2 | ================== 3 | 4 | This file is used to list changes made in each version of the ruby-env cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of ruby-env 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/ruby-env/README.md: -------------------------------------------------------------------------------- 1 | ruby-env Cookbook 2 | ================= 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - ruby-env needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List your cookbook attributes here. 19 | 20 | e.g. 21 | #### ruby-env::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['ruby-env']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### ruby-env::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `ruby-env` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[ruby-env]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write your change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/ruby-env/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['ruby-env']['user'] = "vagrant" 2 | default['ruby-env']['group'] = "vagrant" 3 | default['ruby-env']['version'] = "2.1.1" 4 | default["ruby-env"]["rbenv_url"] = "https://github.com/sstephenson/rbenv" 5 | default["ruby-env"]["ruby-build_url"] = "https://github.com/sstephenson/ruby-build" 6 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/ruby-env/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'ruby-env' 2 | maintainer 'YOUR_COMPANY_NAME' 3 | maintainer_email 'YOUR_EMAIL' 4 | license 'All rights reserved' 5 | description 'Installs/Configures ruby-env' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/ruby-env/recipes/default.rb: -------------------------------------------------------------------------------- 1 | %w{gcc git openssl-devel sqlite-devel}.each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | git "/home/#{node['ruby-env']['user']}/.rbenv" do 8 | repository node["ruby-env"]["rbenv_url"] 9 | action :sync 10 | user node['ruby-env']['user'] 11 | group node['ruby-env']['group'] 12 | end 13 | 14 | template ".bash_profile" do 15 | source ".bash_profile.erb" 16 | path "/home/#{node['ruby-env']['user']}/.bash_profile" 17 | mode 0644 18 | owner node['ruby-env']['user'] 19 | group node['ruby-env']['group'] 20 | not_if "grep rbenv ~/.bash_profile", :environment => { :'HOME' => "/home/#{node['ruby-env']['user']}" } 21 | end 22 | 23 | directory "/home/#{node['ruby-env']['user']}/.rbenv/plugins" do 24 | owner node['ruby-env']['user'] 25 | group node['ruby-env']['group'] 26 | mode 0755 27 | action :create 28 | end 29 | 30 | git "/home/#{node['ruby-env']['user']}/.rbenv/plugins/ruby-build" do 31 | repository node["ruby-env"]["ruby-build_url"] 32 | action :sync 33 | user node['ruby-env']['user'] 34 | group node['ruby-env']['group'] 35 | end 36 | 37 | execute "rbenv install #{node['ruby-env']['version']}" do 38 | command "/home/#{node['ruby-env']['user']}/.rbenv/bin/rbenv install #{node['ruby-env']['version']}" 39 | user node['ruby-env']['user'] 40 | group node['ruby-env']['group'] 41 | environment 'HOME' => "/home/#{node['ruby-env']['user']}" 42 | not_if { File.exists?("/home/#{node['ruby-env']['user']}/.rbenv/versions/#{node['ruby-env']['version']}")} 43 | end 44 | 45 | execute "rbenv global #{node['ruby-env']['version']}" do 46 | command "/home/#{node['ruby-env']['user']}/.rbenv/bin/rbenv global #{node['ruby-env']['version']}" 47 | user node['ruby-env']['user'] 48 | group node['ruby-env']['group'] 49 | environment 'HOME' => "/home/#{node['ruby-env']['user']}" 50 | end 51 | 52 | %w{rbenv-rehash bundler}.each do |gem| 53 | execute "gem install #{gem}" do 54 | command "/home/#{node['ruby-env']['user']}/.rbenv/shims/gem install #{gem}" 55 | user node['ruby-env']['user'] 56 | group node['ruby-env']['group'] 57 | environment 'HOME' => "/home/#{node['ruby-env']['user']}" 58 | not_if "/home/#{node['ruby-env']['user']}/.rbenv/shims/gem list | grep #{gem}" 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /chapter06/site-cookbooks/ruby-env/templates/default/.bash_profile.erb: -------------------------------------------------------------------------------- 1 | # .bash_profile 2 | 3 | # Get the aliases and functions 4 | if [ -f ~/.bashrc ]; then 5 | . ~/.bashrc 6 | fi 7 | 8 | # User specific environment and startup programs 9 | PATH=$PATH:$HOME/bin 10 | export PATH="$HOME/.rbenv/bin:$PATH" 11 | eval "$(rbenv init -)" 12 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/.gitignore: -------------------------------------------------------------------------------- 1 | .kitchen/ 2 | .kitchen.local.yml 3 | Berksfile.lock 4 | Gemfile.lock 5 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_solo 7 | 8 | platforms: 9 | - name: centos-6.5 10 | - name: centos-5.9 11 | 12 | suites: 13 | - name: default 14 | run_list: 15 | - recipe[analog::default] 16 | attributes: 17 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | metadata 4 | 5 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG for analog 2 | 3 | This file is used to list changes made in each version of analog. 4 | 5 | ## 0.1.0: 6 | 7 | * Initial release of analog 8 | 9 | - - - 10 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 11 | 12 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 13 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'test-kitchen', '~> 1.2.0' 3 | gem 'kitchen-vagrant', :group => :integration 4 | gem 'berkshelf' 5 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Ryutaro YOSHIBA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/README.md: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | Installs analog 4 | 5 | Requirements 6 | ============ 7 | 8 | ## Platform: 9 | * RHEL/CentOS 10 | 11 | Attributes 12 | ========== 13 | There is no attribute. 14 | 15 | 16 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/Vagrantfile.erb: -------------------------------------------------------------------------------- 1 | puts "================= this is customized vagrantfile ===================" 2 | 3 | Vagrant.configure("2") do |c| 4 | c.vm.box = "<%= config[:box] %>" 5 | c.vm.box_url = "<%= config[:box_url] %>" 6 | c.vm.hostname = "<%= instance.name %>.vagrantup.com" 7 | 8 | <% if config[:guest] %> 9 | c.vm.guest = <%= config[:guest] %> 10 | <% end %> 11 | <% if config[:username] %> 12 | c.ssh.username = "<%= config[:username] %>" 13 | <% end %> 14 | <% if config[:ssh_key] %> 15 | c.ssh.private_key_path = "<%= config[:ssh_key] %>" 16 | <% end %> 17 | 18 | <% Array(config[:network]).each do |opts| %> 19 | c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>) 20 | <% end %> 21 | 22 | c.vm.synced_folder ".", "/vagrant", disabled: true 23 | <% config[:synced_folders].each do |source, destination, options| 24 | l_source = source.gsub("%{instance_name}", instance.name) 25 | l_destination = destination.gsub("%{instance_name}", instance.name) 26 | opt = (options.nil? ? '' : ", #{options}") 27 | %> 28 | c.vm.synced_folder "<%= l_source %>", "<%= l_destination %>"<%= opt %> 29 | <% end %> 30 | 31 | c.vm.provider :<%= config[:provider] %> do |p| 32 | <% config[:customize].each do |key, value| %> 33 | <% case config[:provider] 34 | when "virtualbox" %> 35 | p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"] 36 | <% when "rackspace" %> 37 | p.<%= key %> = "<%= value%>" 38 | <% when /^vmware_/ %> 39 | <% if key == :memory %> 40 | <% unless config[:customize].include?(:memsize) %> 41 | p.vmx["memsize"] = "<%= value %>" 42 | <% end %> 43 | <% else %> 44 | p.vmx["<%= key %>"] = "<%= value %>" 45 | <% end %> 46 | <% end %> 47 | <% end %> 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/files/default/tests/minitest/default_test.rb: -------------------------------------------------------------------------------- 1 | # vim: ft=ruby 2 | 3 | describe 'analog' do 4 | require 'chef/mixin/shell_out' 5 | include Chef::Mixin::ShellOut 6 | include MiniTest::Chef::Assertions 7 | include MiniTest::Chef::Context 8 | include MiniTest::Chef::Resources 9 | 10 | it 'installs analog' do 11 | # minitest-chef-handler 12 | package('analog').must_be_installed 13 | file('/usr/bin/analog').must_exist 14 | 15 | # minitest 16 | assert File.exist?('/usr/bin/analog') 17 | end 18 | 19 | it 'has correct permission' do 20 | file('/usr/bin/analog').must_have(:mode, "0755") 21 | end 22 | 23 | it 'is version6' do 24 | info = shell_out "analog -v" 25 | info.stdout.must_match(/analog 6/) #this is a regex match 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/files/default/tests/minitest/support/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/metadata.rb: -------------------------------------------------------------------------------- 1 | name "analog" 2 | maintainer "ryuzee" 3 | maintainer_email "ryuzee@gmail.com" 4 | license "MIT" 5 | description "Installs/Configures analog" 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version "0.0.2" 8 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: analog 3 | # Recipe:: default 4 | # 5 | # Author:: Ryuzee 6 | # 7 | # Copyright 2013, Ryutaro YOSHIBA 8 | # 9 | # This software is released under the MIT License. 10 | # http://opensource.org/licenses/mit-license.php 11 | 12 | case node[:platform] 13 | when "centos" 14 | platform_version = node[:platform_version].to_f 15 | 16 | if platform_version >= 6.0 then 17 | rpmfile = "analog-6.0.4-1.x86_64.rpm" 18 | elsif platform_version >= 5.0 then 19 | rpmfile = "analog-6.0.4-1.el5.i386.rpm" 20 | else 21 | raise "This recipe can not be applied to this environment!!" 22 | end 23 | 24 | remote_file "#{Chef::Config[:file_cache_path]}/#{rpmfile}" do 25 | source "http://www.iddl.vt.edu/~jackie/analog/#{rpmfile}" 26 | end 27 | 28 | package 'perl' do 29 | action :install 30 | end 31 | 32 | package "analog" do 33 | action :install 34 | source "#{Chef::Config[:file_cache_path]}/#{rpmfile}" 35 | provider Chef::Provider::Package::Rpm 36 | end 37 | end 38 | 39 | # vim: filetype=ruby.chef 40 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/test/integration/default/bats/default_test.bats: -------------------------------------------------------------------------------- 1 | @test "バイナリが正しい場所にインストールされている" { 2 | ls -la /usr/bin/analog 3 | } 4 | 5 | @test "ファイルに実行権限がある" { 6 | test -x /usr/bin/analog 7 | } 8 | 9 | @test "正しいバージョンである" { 10 | /usr/bin/analog | grep "analog 6.0" 11 | } 12 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/test/integration/default/minitest/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | 3 | describe 'Winning' do 4 | 5 | it "should exist" do 6 | assert File.exists?("/usr/bin/analog") 7 | end 8 | 9 | it "should be executable" do 10 | assert File.executable?("/usr/bin/analog") 11 | end 12 | 13 | it "should be right version" do 14 | assert system("/usr/bin/analog 2>/dev/null | grep 'analog 6.0' 1>/dev/null") 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/test/integration/default/serverspec/localhost/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | include Serverspec::Helper::Exec 3 | include Serverspec::Helper::DetectOS 4 | 5 | RSpec.configure do |c| 6 | c.before :all do 7 | c.os = backend(Serverspec::Commands::Base).check_os 8 | end 9 | c.path = "/sbin:/usr/sbin" 10 | end 11 | 12 | describe file('/usr/bin/analog') do 13 | it { should be_file } 14 | it { should be_mode 755 } 15 | end 16 | 17 | describe command( "/usr/bin/analog 2>/dev/null | grep 'analog 6.0'" ) do 18 | it { should return_exit_status 0 } 19 | end 20 | 21 | describe package('analog') do 22 | it { should be_installed } 23 | end 24 | -------------------------------------------------------------------------------- /chapter07/7.2/analog/test/integration/default/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | require 'pathname' 3 | ### include requirements ### 4 | 5 | include Serverspec::Helper::Exec 6 | include Serverspec::Helper::DetectOS 7 | 8 | RSpec.configure do |c| 9 | # if ENV['ASK_SUDO_PASSWORD'] 10 | # require 'highline/import' 11 | # c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false } 12 | # else 13 | # c.sudo_password = ENV['SUDO_PASSWORD'] 14 | # end 15 | c.before :all do 16 | c.os = backend(Serverspec::Commands::Base).check_os 17 | end 18 | c.path = "/sbin:/usr/sbin" 19 | end 20 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/.gitignore: -------------------------------------------------------------------------------- 1 | .kitchen/ 2 | .kitchen.local.yml 3 | Berksfile.lock 4 | Gemfile.lock 5 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_solo 7 | 8 | platforms: 9 | - name: centos-6.5 10 | 11 | suites: 12 | - name: default 13 | run_list: 14 | - recipe[acme-trac::default] 15 | attributes: 16 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/Berksfile: -------------------------------------------------------------------------------- 1 | site :opscode 2 | 3 | metadata 4 | 5 | cookbook "subversion" ,git:"git://github.com/ryuzee-cookbooks/subversion.git" 6 | cookbook "trac" ,git:"git://github.com/ryuzee-cookbooks/trac.git" 7 | cookbook "apache2" ,git:"git://github.com/ryuzee-cookbooks/apache2.git" 8 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | acme-trac CHANGELOG 2 | =================== 3 | 4 | This file is used to list changes made in each version of the acme-trac cookbook. 5 | 6 | 0.1.0 7 | ----- 8 | - [your_name] - Initial release of acme-trac 9 | 10 | - - - 11 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 12 | 13 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 14 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'test-kitchen', '~> 1.2.0' 3 | gem 'kitchen-vagrant', :group => :integration 4 | gem 'berkshelf' 5 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/README.md: -------------------------------------------------------------------------------- 1 | acme-trac Cookbook 2 | ================== 3 | TODO: Enter the cookbook description here. 4 | 5 | e.g. 6 | This cookbook makes your favorite breakfast sandwhich. 7 | 8 | Requirements 9 | ------------ 10 | TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. 11 | 12 | e.g. 13 | #### packages 14 | - `toaster` - acme-trac needs toaster to brown your bagel. 15 | 16 | Attributes 17 | ---------- 18 | TODO: List you cookbook attributes here. 19 | 20 | e.g. 21 | #### acme-trac::default 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
KeyTypeDescriptionDefault
['acme-trac']['bacon']Booleanwhether to include bacontrue
36 | 37 | Usage 38 | ----- 39 | #### acme-trac::default 40 | TODO: Write usage instructions for each cookbook. 41 | 42 | e.g. 43 | Just include `acme-trac` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[acme-trac]" 50 | ] 51 | } 52 | ``` 53 | 54 | Contributing 55 | ------------ 56 | TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. 57 | 58 | e.g. 59 | 1. Fork the repository on Github 60 | 2. Create a named feature branch (like `add_component_x`) 61 | 3. Write you change 62 | 4. Write tests for your change (if applicable) 63 | 5. Run the tests, ensuring they all pass 64 | 6. Submit a Pull Request using Github 65 | 66 | License and Authors 67 | ------------------- 68 | Authors: TODO: List authors 69 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'acme-trac' 2 | maintainer 'Ryuzee' 3 | maintainer_email 'ryuzee@gmail.com' 4 | license 'MIT' 5 | description 'Installs/Configures acme-trac' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | depends 'iptables' 9 | depends 'subversion' 10 | depends 'trac' 11 | depends 'apache2' 12 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/recipes/default.rb: -------------------------------------------------------------------------------- 1 | include_recipe "subversion" 2 | include_recipe "trac" 3 | include_recipe "iptables" 4 | 5 | iptables_rule "http" 6 | iptables_rule "ssh" 7 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/templates/default/http.erb: -------------------------------------------------------------------------------- 1 | -A FWR -p tcp -m tcp --dport 80 -j ACCEPT 2 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/templates/default/ssh.erb: -------------------------------------------------------------------------------- 1 | -A FWR -p tcp -m tcp --dport 22 -j ACCEPT 2 | -------------------------------------------------------------------------------- /chapter07/7.3/acme-trac/test/integration/default/serverspec/localhost/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | include Serverspec::Helper::Exec 3 | include Serverspec::Helper::DetectOS 4 | 5 | RSpec.configure do |c| 6 | c.before :all do 7 | c.os = backend(Serverspec::Commands::Base).check_os 8 | end 9 | c.path = "/sbin:/user/sbin" 10 | end 11 | 12 | %w{httpd subversion}.each do |package_name| 13 | describe package(package_name) do 14 | it { should be_installed } 15 | end 16 | end 17 | 18 | describe service('httpd') do 19 | it { should be_enabled } 20 | it { should be_running } 21 | end 22 | 23 | describe port(80) do 24 | it { should be_listening } 25 | end 26 | 27 | %w{subversion.conf subversion_sandbox.conf trac_sandbox.conf wsgi.conf}.each do |filename| 28 | describe file("/etc/httpd/conf.d/#{filename}") do 29 | it { should be_file } 30 | it { should be_readable.by_user('root') } 31 | end 32 | end 33 | 34 | describe file("/opt/trac/sandbox") do 35 | it { should be_owned_by 'apache' } 36 | end 37 | 38 | describe file("/opt/svn/sandbox") do 39 | it { should be_owned_by 'apache' } 40 | end 41 | 42 | describe file("/opt/trac_svn_password") do 43 | it { should be_owned_by 'apache' } 44 | it { should contain "admin" } 45 | it { should be_writable.by_user('apache') } 46 | end 47 | 48 | describe command("wget -q http://localhost/sandbox -O - | head -100 | grep trac") do 49 | it { should return_stdout /trac/ } 50 | end 51 | -------------------------------------------------------------------------------- /chapter08/list8-01.txt: -------------------------------------------------------------------------------- 1 | packege "ntp" 2 | -------------------------------------------------------------------------------- /chapter08/list8-02.txt: -------------------------------------------------------------------------------- 1 | package "ntp" do 2 | action :install 3 | -------------------------------------------------------------------------------- /chapter08/list8-03.txt: -------------------------------------------------------------------------------- 1 | execute "shell" do 2 | command "date" 3 | end 4 | -------------------------------------------------------------------------------- /chapter08/list8-04.txt: -------------------------------------------------------------------------------- 1 | execute "shell" do 2 | command "echo "Hello World"" 3 | end 4 | -------------------------------------------------------------------------------- /chapter08/list8-05.txt: -------------------------------------------------------------------------------- 1 | execute "shell" do 2 | command "echo \"Hello World\"" 3 | end 4 | -------------------------------------------------------------------------------- /chapter08/list8-06.txt: -------------------------------------------------------------------------------- 1 | execute "shell" do 2 | command "dataaa" 3 | end 4 | -------------------------------------------------------------------------------- /chapter08/list8-07.txt: -------------------------------------------------------------------------------- 1 | package "php" do 2 | action :install 3 | end 4 | 5 | package "mysql" do 6 | action :install 7 | end 8 | 9 | package "nginx" do 10 | action :install 11 | end 12 | 13 | service "php-fpm" do 14 | action :start 15 | end 16 | 17 | service "mysql" do 18 | action :start 19 | end 20 | 21 | service "nginx" do 22 | action :start 23 | end 24 | -------------------------------------------------------------------------------- /chapter08/list8-08.txt: -------------------------------------------------------------------------------- 1 | %w{php mysql nginx}.each do |name| 2 | package name do 3 | action :install 4 | end 5 | end 6 | 7 | %w{php-fpm mysql nginx}.each do |name| 8 | service name do 9 | action :start 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /chapter08/list8-09.txt: -------------------------------------------------------------------------------- 1 | if node['foo'] == 'bar' 2 | service "apache" do 3 | action :enable 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /chapter08/list8-10.txt: -------------------------------------------------------------------------------- 1 | service "apache" do 2 | action :enable 3 | only_if { node['foo'] == 'bar' } 4 | end 5 | -------------------------------------------------------------------------------- /chapter08/list8-11.txt: -------------------------------------------------------------------------------- 1 | package "ruby" do 2 | action [:install, :upgrade] 3 | end 4 | 5 | package "mysql-server" do 6 | action [:install, :upgrade] 7 | end 8 | 9 | template "/etc/mysqld.conf" do 10 | source "mysqld.conf.erb" 11 | end 12 | 13 | template "/etc/my.conf" do 14 | source "my.conf.erb" 15 | emd 16 | 17 | service "mysqld" do 18 | action [:enable, :restart] 19 | end 20 | -------------------------------------------------------------------------------- /chapter08/list8-12.txt: -------------------------------------------------------------------------------- 1 | package "ruby" do 2 | action [:install, :upgrade] 3 | end 4 | -------------------------------------------------------------------------------- /chapter08/list8-13.txt: -------------------------------------------------------------------------------- 1 | package "mysql-server" do 2 | action [:install, :upgrade] 3 | end 4 | 5 | template "/etc/mysqld.conf" do 6 | source "mysqld.conf.erb" 7 | end 8 | 9 | template "/etc/my.conf" do 10 | source "my.conf.erb" 11 | emd 12 | 13 | service "mysqld" do 14 | action [:enable, :restart] 15 | end 16 | -------------------------------------------------------------------------------- /chapter08/list8-14.txt: -------------------------------------------------------------------------------- 1 | { 2 | 'runlist': [recipe['Ruby'], recipe['MySQL']] 3 | } 4 | -------------------------------------------------------------------------------- /chapter08/list8-15.txt: -------------------------------------------------------------------------------- 1 | include_recipe "Ruby::default" 2 | include_recipe "MySQL::default" 3 | -------------------------------------------------------------------------------- /chapter08/list8-16.txt: -------------------------------------------------------------------------------- 1 | default['versions']['git'] = '1:1.7.9*' 2 | default['versions']['subversion'] = '1.6.17*' 3 | default['versions']['nginx'] = '1.1.19*' 4 | default['versions']['php5'] = '5.3.10*' 5 | -------------------------------------------------------------------------------- /chapter08/list8-17.txt: -------------------------------------------------------------------------------- 1 | packages = %w{git subversion nginx php5} 2 | 3 | packages.each do |pkg| 4 | package pkg do 5 | action [:install, :upgrade] 6 | version node.default[:versions][pkg] 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /chapter08/list8-18.txt: -------------------------------------------------------------------------------- 1 | site 'http://community.opscode.com/api/v1' 2 | cookbook 'timezone' 3 | -------------------------------------------------------------------------------- /chapter08/list8-19.txt: -------------------------------------------------------------------------------- 1 | site 'http://community.opscode.com/api/v1' 2 | cookbook 'td-agent', 3 | :git => 'https://github.com/treasure-data/chef-td-agent' 4 | -------------------------------------------------------------------------------- /chapter08/list8-20.txt: -------------------------------------------------------------------------------- 1 | site :opscode 2 | cookbook 'timezone' 3 | -------------------------------------------------------------------------------- /chapter08/list8-21.txt: -------------------------------------------------------------------------------- 1 | cookbook "artifact", path: "/Users/reset/code/artifact-cookbook" 2 | cookbook "mysql", git: "https://github.com/opscode-cookbooks/mysql.git", branch: "master" 3 | -------------------------------------------------------------------------------- /chapter08/list8-22.txt: -------------------------------------------------------------------------------- 1 | p "One" 2 | execute "apt-get update" do 3 | action :run 4 | end 5 | 6 | p "Two" 7 | package "vim" do 8 | action :install 9 | end 10 | 11 | p "Three" 12 | service "ssh" do 13 | action :restart 14 | end 15 | -------------------------------------------------------------------------------- /chapter08/list8-23.txt: -------------------------------------------------------------------------------- 1 | f = resources("file[/etc/hosts]") 2 | f.mode 00644 3 | f.run_action(:run) 4 | -------------------------------------------------------------------------------- /chapter08/list8-24.txt: -------------------------------------------------------------------------------- 1 | file "/var/hoge4" do 2 | action :create 3 | end 4 | 5 | # コンパイルの時点ではファイルは作成されていない 6 | if !File.exist?("/var/hoge4") then 7 | p "File not found" 8 | end 9 | -------------------------------------------------------------------------------- /chapter08/list8-25.txt: -------------------------------------------------------------------------------- 1 | file "/var/hoge5" do 2 | action :create 3 | end 4 | 5 | #リソースとして実行されればファイルは作成されている 6 | ruby_block "check_file" do 7 | block do if File.exist?("/var/hoge5") then 8 | p "found" 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /chapter08/list8-26.txt: -------------------------------------------------------------------------------- 1 | service "ssh" do 2 | action :nothing 3 | end 4 | 5 | file "/var/hoge" do 6 | action :create 7 | notifies :restart, "service[ssh]", :delayed 8 | end 9 | 10 | file "/var/hoge2" do 11 | action :create 12 | end 13 | -------------------------------------------------------------------------------- /chapter08/list8-27.txt: -------------------------------------------------------------------------------- 1 | require 'chef/knife' 2 | # other require attributes, as needed 3 | 4 | module ModuleName 5 | class SubclassName < Chef::Knife 6 | 7 | deps do 8 | require 'chef/dependency' 9 | # other dependencies, as needed 10 | end 11 | 12 | banner "knife subcommand argument VALUE (options)" 13 | 14 | option :name_of_option, 15 | :short => "-l VALUE", 16 | :long => "--long-option-name VALUE", 17 | :description => "The description for the option.", 18 | :proc => Proc.new { code_to_run } 19 | :boolean => true | false 20 | :default => default_value 21 | 22 | def run 23 | # Ruby code goes here 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /chapter08/list8-28.txt: -------------------------------------------------------------------------------- 1 | provides "hoge" 2 | hoge "my ohai plugin" 3 | -------------------------------------------------------------------------------- /chapter08/list8-29.txt: -------------------------------------------------------------------------------- 1 | provides "hoge" 2 | hoge Mash.new 3 | hoge[:message] = 'my second plugin' 4 | hoge[:list] = [1,10,20] 5 | -------------------------------------------------------------------------------- /chapter08/list8-30.txt: -------------------------------------------------------------------------------- 1 | define :host_porter, :port => 4000, :hostname => nil do 2 | params[:hostname] ||= params[:name] 3 | 4 | directory "/etc/#{params[:hostname]}" do 5 | recursive true 6 | end 7 | 8 | file "/etc/#{params[:hostname]}/#{params[:port]}" do 9 | content "some content" 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /chapter08/list8-31.txt: -------------------------------------------------------------------------------- 1 | host_porter node['hostname'] do 2 | port 4000 3 | end 4 | 5 | host_porter "www1" do 6 | port 4001 7 | end 8 | -------------------------------------------------------------------------------- /chapter08/list8-32.txt: -------------------------------------------------------------------------------- 1 | actions :create, :delete, :touch, :create_if_missing 2 | attribute :backup, :kind_of => [ Integer, FalseClass ] 3 | attribute :group, :regex => [ /^([a-z]|[A-Z]|[0-9]|_|-)+$/, /^\d+$/ ] 4 | attribute :mode, :regex => /^0?\d{3,4}$/ 5 | attribute :owner, :regex => [ /^([a-z]|[A-Z]|[0-9]|_|-)+$/, /^\d+$/ ] 6 | attribute :path, :kind_of => String 7 | attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/ 8 | -------------------------------------------------------------------------------- /chapter08/list8-33.txt: -------------------------------------------------------------------------------- 1 | def whyrun_supported? 2 | true 3 | end 4 | 5 | # インラインで実行 6 | use_inline_resources 7 | 8 | # :deleteアクションに対応する処理 9 | action :delete do 10 | if user_exists?(example.user) 11 | cmdStr = "rabbitmqctl delete_user #{new_resource.user}" 12 | execute cmdStr do 13 | new_resource.updated_by_last_action(true) 14 | end 15 | end 16 | end 17 | 18 | # アクション内で使う任意の関数の定義 19 | def user_exists?(name) 20 | true 21 | end 22 | -------------------------------------------------------------------------------- /chapter09/list09-01.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1 chef-test01 localhost localhost.localdomain localhost4 localhost4.localdomain4 2 | -------------------------------------------------------------------------------- /chapter09/list09-02.txt: -------------------------------------------------------------------------------- 1 | log_level :info 2 | log_location STDOUT 3 | chef_server_url 'https://' 4 | validation_client_name 'chef-validator' 5 | -------------------------------------------------------------------------------- /chapter09/list09-03.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db01", 3 | "public_key": null, 4 | "admin": false, 5 | "json_class": "Chef::ApiClient", 6 | "chef_type": "client" 7 | } 8 | -------------------------------------------------------------------------------- /chapter09/list09-05.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db01", 3 | "chef_environment": "_default", 4 | "json_class": "Chef::Node", 5 | "automatic": { 6 | }, 7 | "normal": { 8 | }, 9 | "chef_type": "node", 10 | "default": { 11 | }, 12 | "override": { 13 | }, 14 | "run_list": [ 15 | "recipe[sample]" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /chapter09/list09-06.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "description": "", 4 | "json_class": "Chef::Role", 5 | "default_attributes": { 6 | }, 7 | "override_attributes": { 8 | }, 9 | "chef_type": "role", 10 | "run_list": [ 11 | "recipe[mysql]" 12 | ], 13 | "env_run_lists": { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapter09/list09-07.txt: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db01", 3 | "chef_environment": "_default", 4 | "normal": { 5 | }, 6 | "run_list": [ 7 | "role[db]" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /chapter10/list10-01.txt: -------------------------------------------------------------------------------- 1 | chef_server_url 'https://xxx.xxx.xxx.xxx' 2 | node_name 'hostname' 3 | -------------------------------------------------------------------------------- /chapter10/list10-02.txt: -------------------------------------------------------------------------------- 1 | set -- `cat /proc/cmdline` 2 | for x in $*; do 3 | case $x in node*) 4 | echo $x >> /tmp/ks-nodename 5 | ;; 6 | esac; 7 | done 8 | 9 | cat /tmp/ks-nodename | sed -e "s/\(.*\)node=\(.*\)/node_name '\\2'/" >> /etc/chef/client.rb 10 | -------------------------------------------------------------------------------- /chapter10/list10-03.txt: -------------------------------------------------------------------------------- 1 | ks=http://xxx.xxx.xxx.xxx/ks/CentOS_6.5_pxe.txt load initrd=centos_6_5_x86_64/initrd.img devfs=nomount ksdevice=eth0 BOOT_IMAGE=centos_6_5_x86_64/vmlinuz node=chef-test01 2 | -------------------------------------------------------------------------------- /chapter10/list10-04.txt: -------------------------------------------------------------------------------- 1 | monitoring = { 2 | :apache2_status => { 3 | :checker => "http", 4 | :level => "critical", 5 | :interval => 60, 6 | :params => { 7 | :port => node[:apache2][:http_port], 8 | :uri => node[:apache2][:monitor_url] 9 | } 10 | } 11 | } 12 | --------------------------------------------------------------------------------