primeiros passos com chef

32
rr CHEF @cassianoleal Sunday, April 21, 13

Upload: cassiano-leal

Post on 07-May-2015

332 views

Category:

Technology


1 download

DESCRIPTION

Um workshop para quem está começando com a ferramenta Opscode Chef. Apresentado no Idéias em Produção, em 21 de Abril de 2013 no escritório da ThoughtWorks Brasil em Porto Alegre.

TRANSCRIPT

Page 1: Primeiros Passos com Chef

!r"#$"r% !&''%()#CHEF

@cassianoleal

Sunday, April 21, 13

Page 2: Primeiros Passos com Chef

?CHEFM&' &*+&,,) q-$ .

Sunday, April 21, 13

Page 3: Primeiros Passos com Chef

Sunday, April 21, 13

Page 4: Primeiros Passos com Chef

Sunday, April 21, 13

Page 5: Primeiros Passos com Chef

RUBY"+

Sunday, April 21, 13

Page 6: Primeiros Passos com Chef

knife. & f$rr&#$+/& 0$ ,"+1&0$ ()#&+0) 0) C1$f

workstation+& '-&

Sunday, April 21, 13

Page 7: Primeiros Passos com Chef

workstation'$/-!Git

Vagrant

VirtualBox

Ruby

Chef

Sunday, April 21, 13

Page 8: Primeiros Passos com Chef

$ vagrant box add opscode-ubuntu1204 \http://<ip>:8000/opscode_ub1204.box

Downloading or copying the box...Extracting box...te: 280M/s, Estimated time remaining: 0:00:01)Successfully added box 'opscode-ubuntu1204' with provider 'virtualbox'!

Sunday, April 21, 13

Page 9: Primeiros Passos com Chef

REPOC1$f

git clone git://github.com/opscode/chef-repo

certificates/.chef/config/cookbooks/data_bags/environments/roles/

Sunday, April 21, 13

Page 10: Primeiros Passos com Chef

knife.rb.(1$f/

current_path = File.expand_path(File.dirname(__FILE__))cookbook_path [ "#{current_path}/../cookbooks" ]

Sunday, April 21, 13

Page 11: Primeiros Passos com Chef

$ knife cookbook create my_app

$ cd cookbooks/my_app

$ ls

Sunday, April 21, 13

Page 12: Primeiros Passos com Chef

COOKBOOK#2_&!!

CHANGELOG.mdREADME.mdattributes/definitions/files/libraries/metadata.rbproviders/recipes/resources/templates/

Sunday, April 21, 13

Page 13: Primeiros Passos com Chef

COOKBOOK#2_&!!

CHANGELOG.mdREADME.mdattributes/definitions/files/libraries/metadata.rbproviders/recipes/resources/templates/

Sunday, April 21, 13

Page 14: Primeiros Passos com Chef

default.rbr$("!$'/

package ‘apache2’

directory “/var/www/my_app” do owner ‘www-data’ group ‘www-data’ mode 0755 action :createend

Sunday, April 21, 13

Page 15: Primeiros Passos com Chef

$ vagrant init opscode_ubuntu1204

Sunday, April 21, 13

Page 16: Primeiros Passos com Chef

VagrantfileVagrant.configure("2") do |config| config.vm.box = "opscode_ubuntu1204"

config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "../../cookbooks" chef.add_recipe "my_app::default" endend

Sunday, April 21, 13

Page 17: Primeiros Passos com Chef

$ vagrant up

(...)======================================================Error executing action `install` on resource 'package[apache2]'======================================================

Chef::Exceptions::Exec----------------------

apt-get -q -y install apache2=2.2.22-1ubuntu1.2 returned 100, expected 0

(...)

Sunday, April 21, 13

Page 18: Primeiros Passos com Chef

$ vagrant ssh$ sudo apt-get -q -y install apache2=2.2.22-1ubuntu1.2

Sunday, April 21, 13

Page 19: Primeiros Passos com Chef

execute "update apt cache" do command "apt-get update" user 'root' action :runend

Sunday, April 21, 13

Page 20: Primeiros Passos com Chef

SERVERC1$f

https://community.opscode.com/users/newSunday, April 21, 13

Page 21: Primeiros Passos com Chef

[your_organization_name]-validator.pem[your_username].pemknife.rb

REPOC1$f

git clone git://github.com/opscode/chef-repo

$ knife client listSunday, April 21, 13

Page 22: Primeiros Passos com Chef

http://community.opscode.com/cookbooks/

COMMUNITYw$3"/$

Sunday, April 21, 13

Page 23: Primeiros Passos com Chef

$ knife cookbook site install apache2

$ git status# On branch master# Your branch is ahead of 'origin/master' by 1 commit.# (use "git push" to publish your local commits)## Untracked files:# (use "git add <file>..." to include in what will be committed)## .chef/nothing added to commit but untracked files present (use "git add" to track)

Sunday, April 21, 13

Page 24: Primeiros Passos com Chef

GIT,)4

Sunday, April 21, 13

Page 25: Primeiros Passos com Chef

berkshelf

BUNDLER !&r& ())5b))5'

$ gem install berkshelf

Sunday, April 21, 13

Page 26: Primeiros Passos com Chef

Berksfilesite :opscodecookbook 'apt'cookbook 'apache2'

$ berks install$ berks upload

Sunday, April 21, 13

Page 27: Primeiros Passos com Chef

$ knife cookbook create my_app

Sunday, April 21, 13

Page 28: Primeiros Passos com Chef

default.rbr$("!$'/

directory “#{node[:my_app][:root]}/my_app” do owner node[:apache][:user] group node[:apache][:group] mode 0755 action :createend

Sunday, April 21, 13

Page 29: Primeiros Passos com Chef

chef-repo/roles/my_app.rb

name 'my_app'description 'A single application server'run_list( 'recipe[apt::default]', 'recipe[apache2::default]', 'recipe[my_app]')

Sunday, April 21, 13

Page 30: Primeiros Passos com Chef

$ knife cookbook upload my_app$ knife role from file roles/my_app.rb

$ knife cookbook list$ knife role list

$ knife role show my_app

Sunday, April 21, 13

Page 31: Primeiros Passos com Chef

Templates

N!"# A$$r%b&$#'

S#(r)*Bootstrap

S#rv%)# / N!$%+#'

2 caminhos:- alguém sugere o que fazer- seguir o learnchef EC2

LWRP

Sunday, April 21, 13