4. Open Source Provisioning Toolchain
アプリケーションサービス導入
システム設定
Cloud or VM
イメージ起動
OS
インストール
オーケストレーション
コンフィグレーション
ブートストラッピング
Open Source Provisioning Toolchain
http://cdn.oreillystatic.com/en/assets/1/event/48/Provisioning%20Toolchain%20Presentation.pdf
プロビジョニングアクティビティ
Capistrano
Fabric
Maven
CFEngine
Puppet
Chef
Ansible
Kickstart
Vagrant
Docker
← ここ
5. Infrastructure as Code
• インフラをコードで記述
Puppet
package { 'nginx'
ensure => installed,
}
service { 'nginx'
ensure => running,
enable => true,
}
Chef
package 'nginx' do
action :install
end
service 'nginx' do
action [ :enable, :start ]
end
6. 宣言的
• 手順ではなく、「あるべき状態」を記述
命令的(Shell)
$ sudo yum install –y nginx
$ sudo /sbin/chkconfig –level 2345 nginx on
$ sudo service nginx start
宣言的(Chef)
package 'nginx' do
action :install
end
service 'nginx' do
action [ :enable, :start ]
end
34. Serverspec
• サーバの状態をテストするためのフレームワーク
• サーバに直接アクセス(Exec、SSH)してコマンドを実行するので、(Puppet とかChef とか)設定管理
ツールに依存しない
• 内部でRSpec を利用していて、宣言的にテストコードが書ける
http://serverspec.org/
...
describe package('httpd') do
it { should be_installed }
end
describe service('httpd') do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
httpd パッケージが
インストールされているか?
httpd サービスが
動作しているか?
80番ポートが
Listen か?
36. テストコード
• 初期化時に作成されるサンプルを削除
$ rm spec/hoge/sample_spec.rb
• Nginx パッケージ・サービスをテストコードを作成
spec/hoge/nginx_spec.rb
require 'spec_helper'
describe package('nginx') do
it { should be_installed }
end
describe service('nginx') do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
37. Serverspec の実行
• テストの実行(成功時の例)
$ rake spec
c:/opscode/chefdk/embedded/bin/ruby.exe -
I'c:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/rspec-support-
3.1.1/lib';'c:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/rspec-core-3.1.5/lib'
c:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/rspec-core-3.1.5/exe/rspec --pattern
'spec/hoge/*_spec.rb'
Package "nginx"
should be installed
Service "nginx"
should be enabled
should be running
Port "80"
should be listening
Finished in 2.08 seconds (files took 1.61 seconds to load)
4 examples, 0 failures
43. テストコード
• テストコードを用意
fuga/test/integration/default/serverspec/nginx_spec.rb
require 'serverspec'
set :backend, :exec
describe package('nginx') do
it { should be_installed }
end
describe service('nginx') do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
44. kitchen create
• テスト用のVM を起動
$ kitchen create
-----> Starting Kitchen (v1.2.1)
-----> Creating <default-centos-65>...
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'opscode-centos-6.5'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: default-centos-65_default_1413889162414_90686
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Machine not provisioning because `--no-provision` is specified.
Vagrant instance <default-centos-65> created.
Finished creating <default-centos-65> (0m52.44s).
-----> Kitchen is finished. (0m53.07s)
• ステータスを確認
$ kitchen list
Instance Driver Provisioner Last Action
default-centos-65 Vagrant ChefSolo Created
45. kitchen converge
• Chef のCookbook/Recipe を適用
$ kitchen converge
-----> Starting Kitchen (v1.2.1)
-----> Converging <default-centos-65>...
Preparing files for transfer
Resolving cookbook dependencies with Berkshelf 3.1.5...
Removing non-cookbook files before transfer
-----> Installing Chef Omnibus (true)
downloading https://www.getchef.com/chef/install.sh
to file /tmp/install.sh
trying wget...
trying curl...
<snip>
Installing Chef
installing with rpm...
<snip>
Compiling Cookbooks...
Converging 5 resources
<snip>
Chef Client finished, 10/11 resources updated in 134.641277799 seconds
Finished converging <default-centos-65> (2m53.56s).
-----> Kitchen is finished. (2m56.37s)
• ステータスを確認
$ kitchen list
Instance Driver Provisioner Last Action
default-centos-65 Vagrant ChefSolo Converged
46. kitchen setup
• テスト用の仮想マシンに必要なパッケージをセットアップ
$ kitchen setup
-----> Starting Kitchen (v1.2.1)
-----> Setting up <default-centos-65>...
Fetching: thor-0.19.0.gem (100%)
Fetching: busser-0.6.2.gem (100%)
Successfully installed thor-0.19.0
Successfully installed busser-0.6.2
2 gems installed
-----> Setting up Busser
Creating BUSSER_ROOT in /tmp/busser
Creating busser binstub
Plugin serverspec installed (version 0.5.3)
-----> Running postinstall for serverspec plugin
Finished setting up <default-centos-65> (0m29.77s).
-----> Kitchen is finished. (0m32.89s)
• ステータスを確認
$ kitchen list
Instance Driver Provisioner Last Action
default-centos-65 Vagrant ChefSolo <Not Created>
47. kitchen verify
• テストを実行
$ kitchen verify
-----> Starting Kitchen (v1.2.1)
-----> Verifying <default-centos-65>...
Removing /tmp/busser/suites/serverspec
Uploading /tmp/busser/suites/serverspec/nginx_spec.rb (mode=0644)
-----> Running serverspec test suite
/opt/chef/embedded/bin/ruby -I/tmp/busser/suites/serverspec -I/tmp/busser
/gems/gems/rspec-support-3.1.2/lib:/tmp/busser/gems/gems/rspec-core-3.1.7/lib /o
pt/chef/embedded/bin/rspec --pattern /tmp/busser/suites/serverspec/**/*_spec.
rb --color --format documentation --default-path /tmp/busser/suites/serverspec
Package "nginx"
should be installed
Service "nginx"
should be enabled
should be running
Port "80"
should be listening
Finished in 0.1954 seconds (files took 0.31729 seconds to load)
4 examples, 0 failures
Finished verifying <default-centos-65> (0m1.89s).
-----> Kitchen is finished. (0m4.71s)
• ステータスを確認
$ kitchen list
Instance Driver Provisioner Last Action
default-centos-65 Vagrant ChefSolo Verified
48. kitchen destroy
• テスト用のVM を破棄
$ kitchen destroy
-----> Starting Kitchen (v1.2.1)
-----> Destroying <default-centos-65>...
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
Vagrant instance <default-centos-65> destroyed.
Finished destroying <default-centos-65> (0m6.75s).
-----> Kitchen is finished. (0m9.74s)
• ステータスを確認
$ kitchen list
Instance Driver Provisioner Last Action
default-centos-65 Vagrant ChefSolo Verified
49. kitchen test
• kitchen test コマンドでこれまでの作業を一気通貫に実行できる
$ kitchen test
-----> Cleaning up any prior instances of <default-centos-65>
-----> Destroying <default-centos-65>...
...
-----> Starting Kitchen (v1.2.1)
...
-----> Creating <default-centos-65>...
...
-----> Converging <default-centos-65>...
...
-----> Setting up <default-centos-65>...
...
-----> Verifying <default-centos-65>...
...
-----> Destroying <default-centos-65>...
...
-----> Kitchen is finished. (4m20.90s)
clean up
create
converge
setup
verify
destroy
50. インフラCI
オンプレミスクラウド
①通知(server side hook)
Git レポジトリGit レポジトリ
②ローカルもしくはリモートで
“kitchen test” を実行
git push/merge
git push/merge
or Pull request
② “kitchen test” を実行
テスト用VM には
クラウドサービスを利用
クラウドサービス
外部CI ツール
CI ツール
①通知(web hook)
55. Quagga Chef Provider の例
Quagga OSPF Chef Provider による設定
spine_ports = ["lo:1","swp21","swp22","swp23","swp24"]
spine_ports_options = ["ip ospf area #{node.quagga.ospf.area}","ip ospf network point-to-point"]
# merging the options into spine_ports
ospf = {}
spine_ports.each do |i|
ospf[i]=spine_ports_options
end
# implement ospf unnumbered interfaces
spine_ports.each do |port|
ifconfig "#{node.quagga.loopback}/32" do
device "#{port}"
end
end
# remove these interfaces from being passive
ospf_options=[]
spine_ports.each do |i|
ospf_options << "no passive-interface #{i}"
end
quagga_ospf "#{node.quagga.ospf.area}" do
loopback node.quagga.loopback
interfaces ospf
protocols ["static"]
ospf_op
end
Network Management and Automation with Chef (by Bao Nguyen)
http://engineering.ooyala.com/blog/network-management-and-automation-chef
インターフェイス周りの設定
OSPF 周りのの設定