Transcript
Page 1: Chef infrastructure as code - paris.rb

Infrastructure as codewith Chef

Page 2: Chef infrastructure as code - paris.rb

<Nicolas Ledez>

Page 3: Chef infrastructure as code - paris.rb
Page 4: Chef infrastructure as code - paris.rb
Page 5: Chef infrastructure as code - paris.rb
Page 6: Chef infrastructure as code - paris.rb
Page 7: Chef infrastructure as code - paris.rb
Page 8: Chef infrastructure as code - paris.rb
Page 9: Chef infrastructure as code - paris.rb

Orange Business Service

IT&L@bs

Page 10: Chef infrastructure as code - paris.rb

IT&L@bsGit

Ruby

Cloud

Architecture

Page 11: Chef infrastructure as code - paris.rb
Page 12: Chef infrastructure as code - paris.rb
Page 13: Chef infrastructure as code - paris.rb

Human coders news / Ruby

Page 14: Chef infrastructure as code - paris.rb

http://rennesdevops.fr/

@Rennesdevops

https://groups.google.com/forum/#!forum/rennesdevops

Page 15: Chef infrastructure as code - paris.rb

@nledez

Page 16: Chef infrastructure as code - paris.rb

</Nicolas Ledez>

Page 17: Chef infrastructure as code - paris.rb

DevOps ?

Page 18: Chef infrastructure as code - paris.rb

Avec du "Opscode" dedans

Page 19: Chef infrastructure as code - paris.rb

Chef ?

http://www.vectorarts.net/people/free-woman-chef-tree-vector-graphics/

Page 20: Chef infrastructure as code - paris.rb
Page 21: Chef infrastructure as code - paris.rb

Il faut (pour faire comme moi)

Un Mac (sinon lis la doc)

Ruby (avec rbenv, rvm, pik, ce que tu veux)

Virtual Box (Sinon c'est plus cher et + dur)

Page 22: Chef infrastructure as code - paris.rb

Installation

% gem install chef --no-ri --no-rdocSuccessfully installed chef-11.4.41 gem installed

Page 23: Chef infrastructure as code - paris.rb

Création d'un compte

https://community.opscode.com

/users/new

Page 24: Chef infrastructure as code - paris.rb

Les fichiers

Page 25: Chef infrastructure as code - paris.rb

Ça vous donne :===== .chef/knife.rb current_dir = File.dirname(__FILE__) log_level :info log_location STDOUT node_name "nledez-demo" client_key "#{current_dir}/nledez-demo.pem" validation_client_name "nledez-demo-validator" validation_key "#{current_dir}/nledez-demo-validator.pem" chef_server_url "https://api.opscode.com/organizations/nledez-demo" cache_type 'BasicFile' cache_options( :path => "#{ENV['HOME']}/.chef/checksums" ) cookbook_path ["#{current_dir}/../cookbooks"]

Page 26: Chef infrastructure as code - paris.rb

Et aussi :

===== .chef/nledez-demo-validator.pem -----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEAtuj2RaZHccGQzTVo++ZMdO9NHhmOM+KjtBe5xdKcsRjdeJBZ DxcYt+gf/blIsf5V/MVt5WJDdaovwEXddwUnpnIAtKClOKqq7TZ0j6Z9LGmgSZ3X dRPYb7J3SvVgJCc3RIjvw5lBF1QANHZTMrymUptvJZQkqn9YstYrY128HaBJJqux m4dRFTuOZtEfM7PTioeyMg95WJkH3qrtz7ndsx/X1dUUOAl5xalj3g== -----END RSA PRIVATE KEY-----

Page 27: Chef infrastructure as code - paris.rb

Et enfin :

===== .chef/nledez-demo.pem -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEAwCOC8jpxa+wqNsOKmwpwXyODDVLMkrO74LyK0vH1Rsn/MHO8 YAS/TNtj36Y/B/0sZSJSw1KEI99vie36M61XxVMytJRTGvOKHAx4HkHm+gdz5vi1 2JhkYo5JRCMzBXeMXgcrh8IDeUmdrjb2P/4yBYLPZrSSjwypbRrfB/Yx8cOZ9XKV JZYBAoGANwZ157/Afyus7ZIb5Rh3iCxCPqJKtmo257gh4Yzbv/MEcStI2Ync3k04 mCQ6MlSCH4XaEg6NhMDBy/ahnJ3gf8wzPsxDYbVMCgai9/RRxRJ5DTgDkyDma6f/ fbd1ldFNWrAyix7mOsIPLElEyYczVoYZDJsMf9EETwbvUArrcOo= -----END RSA PRIVATE KEY-----

Page 28: Chef infrastructure as code - paris.rb

Ça donne :% for i in node client cookbook environment role ; do echo "===== $i:" knife $i listdone===== node:!===== client:nledez-demo-validator===== cookbook:!===== environment:_default===== role:

Page 29: Chef infrastructure as code - paris.rb

Un repo tout prêt

% cd /mon/repertoire/de/chef% lsGemfile Gemfile.lock README.md% git clone https://github.com/opscode/chef-repo.gitCloning into 'chef-repo'...remote: Counting objects: 209, done.remote: Compressing objects: 100% (126/126), done.remote: Total 209 (delta 75), reused 170 (delta 49)Receiving objects: 100% (209/209), 35.05 KiB, done.Resolving deltas: 100% (75/75), done.

Page 30: Chef infrastructure as code - paris.rb

Pour le compléter% cd chef-repo% lsLICENSE Rakefile chefignore cookbooks environmentsREADME.md certificates config data_bags roles% rm -rf .git% mv README.md ../README-chef.md # Si vous voulez garder votre README.md d'origine% mv * ..mv .gitignore ..% cd ..% git add .gitignore *% git commit -m "Add a clean chef repo"[master 2e7e758] Add a clean chef repo11 files changed, 545 insertions(+), 1 deletion(-)create mode 100644 LICENSEcreate mode 100644 README-chef.mdcreate mode 100644 Rakefilecreate mode 100644 certificates/README.mdcreate mode 100644 chefignorecreate mode 100644 config/rake.rbcreate mode 100644 cookbooks/README.mdcreate mode 100644 data_bags/README.mdcreate mode 100644 environments/README.mdcreate mode 100644 roles/README.md

Page 31: Chef infrastructure as code - paris.rb

Premier CookbookEn mode TDD

Page 32: Chef infrastructure as code - paris.rb

TDD ?

Page 33: Chef infrastructure as code - paris.rb

Création du cookbook% knife cookbook create nginx_unicorn% git status# On branch master# Untracked files:# cookbooks/nginx_unicorn/% git add cookbooks/nginx_unicorn ; git commit -m "Fresh nginx_unicorn cookbook"[master 5be0d84] Fresh nginx_unicorn cookbook4 files changed, 95 insertions(+)create mode 100644 cookbooks/nginx_unicorn/CHANGELOG.mdcreate mode 100644 cookbooks/nginx_unicorn/README.mdcreate mode 100644 cookbooks/nginx_unicorn/metadata.rbcreate mode 100644 cookbooks/nginx_unicorn/recipes/default.rb

Page 34: Chef infrastructure as code - paris.rb

Sanity checks

% bundle exec foodcritic cookbooks/nginx_unicornFC008: Generated cookbook metadata needs updating: cookbooks/nginx_unicorn/metadata.rb:2FC008: Generated cookbook metadata needs updating: cookbooks/nginx_unicorn/metadata.

Page 35: Chef infrastructure as code - paris.rb

Édition des metadatas% cd cookbooks/nginx_unicorn% vi metadata.rb # Ou l'éditeur texte que vous voulez

name 'nginx_unicorn'maintainer 'YOUR_COMPANY_NAME'maintainer_email 'YOUR_EMAIL'license 'All rights reserved'description 'Installs/Configures nginx_unicorn'long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))version '0.1.0'

Page 36: Chef infrastructure as code - paris.rb

Les correctionsname 'nginx_unicorn'maintainer 'Ledez Incorporated'maintainer_email '[email protected]'license 'All rights reserved'description 'Installs/Configures nginx & unicorn'long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))version '0.1.0'

% bundle exec foodcritic .

Page 37: Chef infrastructure as code - paris.rb

Premier lancement de tests

% bundle exec knife cookbook create_specs nginx_unicorn** Creating specs for cookbook: nginx_unicorn% bundle exec rspec --color*!Pending:nginx_unicorn::default should do something# Your recipe examples go here.# ./spec/default_spec.rb:5!Finished in 0.00045 seconds1 example, 0 failures, 1 pending

Page 38: Chef infrastructure as code - paris.rb

Le testrequire 'chefspec'!describe 'nginx_unicorn::default' do  let (:chef_run) { ChefSpec::ChefRunner.new.converge 'nginx_unicorn::default' }  it 'should do something' do    pending 'Your recipe examples go here.'  endend

it 'should deploy nginx' do  runner = expect(chef_run)!  runner.to install_package "nginx"end

Page 39: Chef infrastructure as code - paris.rb

Le test KO% bundle exec rspec --colorCompiling Cookbooks...F!Failures:!1) nginx_unicorn::default should deploy nginxFailure/Error: runner.to install_package "nginx"No package resource named 'nginx' with action :install found.# ./spec/default_spec.rb:8:in `block (2 levels) in '!Finished in 0.00393 seconds1 example, 1 failure!Failed examples:!rspec ./spec/default_spec.rb:5 # nginx_unicorn::default should deploy nginx

Page 40: Chef infrastructure as code - paris.rb

Le code

## Cookbook Name:: nginx_unicorn# Recipe:: default## Copyright 2013, Ledez Incorporated## All rights reserved - Do Not Redistribute#package "nginx" do  action :installend

Page 41: Chef infrastructure as code - paris.rb

Qui passe vert

% bundle exec rspec --colorCompiling Cookbooks....!

Finished in 0.00429 seconds1 example, 0 failures

Page 42: Chef infrastructure as code - paris.rb

Démo

Page 43: Chef infrastructure as code - paris.rb

QR ?

Page 44: Chef infrastructure as code - paris.rb

Merci

Page 45: Chef infrastructure as code - paris.rb

@nledez nicolas.ledez.net


Top Related