Slide 1

Slide 1 text

diff puppet chef Ruby Tuesday #23

Slide 2

Slide 2 text

Speakers Ash Wu Vincent about.me/hSATAC about.me/v1nc3ntlaw

Slide 3

Slide 3 text

DevOps ● DevOps => Bridge and oil between developers and operators. ● Developer => Code ● Operator => Infrastructure ● Infrastructure as Code

Slide 4

Slide 4 text

Infrastructure as Code ● Automation ● Configuration as document ● Configuration as code ● Better reuse ● Versioning ● Testing ● Continuous Integration

Slide 5

Slide 5 text

Puppet ● Open source ● Written in Ruby ● Has its own DSL ● You define the desired states (What does it look like) ● Puppet will do the rest (How should it be done) ● Used by Wikimedia, Rackspace, Zynga, Github, Google, Oracle...

Slide 6

Slide 6 text

Masterless Puppet ● Define ● Simulate ● Enforce ● Report

Slide 7

Slide 7 text

Master-Agent Puppet ● Send facts ● Compile ● Query ● Enforce ● Report

Slide 8

Slide 8 text

Resource ● File ● User ● Group ● Package ● Service ● Mount ● Cron ● ...... http://docs.puppetlabs.com/references/latest/type.html

Slide 9

Slide 9 text

Dependencies ● Code order != Execute order ● Before / Require ● Notify / Subscribe ● Chaining Ex: Package -> File ~> Service ● Autorequire ● Puppet is smart enough so solve some dependencies for you. Ex: file and parent folder, user and ssh-key ● Stage

Slide 10

Slide 10 text

Puppet DSL ● Variables, Conditions, Facts ● Modules, Classes ● Templates ● Puppet > 2.6.x manifests can be written in Ruby https://puppetlabs.com/blog/ruby-dsl/

Slide 11

Slide 11 text

Puppet Community ● Modules, Classes ● Puppet Forge http://forge.puppetlabs.com/ ● Most of them are for debian/ubuntu/centos ● `puppet module install puppetlabs-apache` install, list, search, uninstall, upgrade ● Contribute please

Slide 12

Slide 12 text

Enterprise Puppet ● Not a service ● Charges by node number (Free < 10 nodes) Node number detect from cert sign ● Whole package installer ● Web GUI ● Support ● https://puppetlabs.com/puppet/enterprise-vs-open- source/ ● https://puppetlabs.com/puppet/whats-new/

Slide 13

Slide 13 text

Puppet Testing ● Syntax check - Puppet-lint http://puppet-lint.com/ ● Unit test - rspec-puppet http://rspec-puppet.com/ ● Multiple OS test - Puppet Playground https://github.com/example42/puppet-playground ● Fizzgig - Fast puppet unit tests https://github.com/philandstuff/fizzgig

Slide 14

Slide 14 text

Puppet Testing Articles ● https://puppetlabs.com/blog/testing-puppet-code-in-the- puppet-playground/ ● https://puppetlabs.com/blog/test-driven-development- with-puppet/ ● http://puppetlabs.com/blog/verifying-puppet-checking- syntax-and-writing-automated-tests/

Slide 15

Slide 15 text

Puppet File Server ● Puppet masters built-in ● `puppet://{server}/{mount}/{path}` ● `puppet:///modules/test_module/testfile.txt` => /etc/puppet/modules/test_module/files/testfile.txt ● Custom mount point allow /hostname/ allow cidr default deny * http://docs.puppetlabs.com/guides/file_serving.html

Slide 16

Slide 16 text

Chef Intro ● Opscode, Inc. ● Just Enough Ruby for Chef ○ http://docs.opscode.com/just_enough_ruby_for_chef.html ● Chef 10 => 11 Server ○ Released at 2013 Feb. Rewrite of the core API server in Erlang, which call Erchef. Migrated the WebUI from merb to Rails 3.

Slide 17

Slide 17 text

http://docs.opscode.com/chef_overview.html

Slide 18

Slide 18 text

Workstation ● knife ○ Command tool helps user manage Chef. ● knife-ec2 ○ Plugin extend knife subcommand ec2 manage AWS EC2 servers. ● knife-github-cookbooks ○ Plugin extend knife subcommand github download cookbooks from github repository. ○ $ knife cookbook github install USER/REPO http://docs.opscode.com/knife.html

Slide 19

Slide 19 text

Resource Resource ● Package ● User ● Cron ● Git ● Script ● Ruby ● more... Provider ● Chef::Provider::Package::Apt ● Chef::Provider::Package::Yum package "tar" do Chef::Provider::Package::Yum action :install end http://docs.opscode.com/resource.html

Slide 20

Slide 20 text

Cookbook Logic about install and configure packages. ● Attributes ● Files ● Recipes ● Templates

Slide 21

Slide 21 text

Files ● cookbook_file ○ copying files from a cookbook ● remote_file ○ transferring files from remote locations

Slide 22

Slide 22 text

Data Bags ● Store data in a JSON file. user02.json ○ { "id": "user02", "uid": "1002", "gid": "1002", "public_key": "ssh-rsa ABCDE..." } ● Encrypt / Decrypt ○ Store sensitive information

Slide 23

Slide 23 text

Opscode Community http://community.opscode.com/ ● Opscode maintains cookbooks ● Community authored cookbooks ● $ knife cookbook site install apache2

Slide 24

Slide 24 text

Chef Server ● Opscode Hosted Chef Server ○ 5 Nodes Free ● Install Chef Server ○ Ubuntu (deb) ○ Enterprise Linux (rpm) ● AWS OpsWorks Richard Lee - Polydice, Inc. Does OpsWorks Work? ○ https://speakerdeck.com/dlackty/does-opsworks-work

Slide 25

Slide 25 text

Chef Solo ● Run provision locally without Chef Server. ● chef-solo is a limited-functionality version ● chef-solo + capistrano ○ https://github.com/doitian/chef-solo-repo http://docs.opscode.com/chef_solo.html

Slide 26

Slide 26 text

Chef TEST ● cucumber-chef ● chefspec ○ RSpec for chef cookbooks ● foodcritic ○ Lint tool ● test-kitchen ○ Framework for running integration tests in an isolated environment ● minitest-chef-handler ○ Run minitest after your Chef recipes to check the system status

Slide 27

Slide 27 text

diff puppet chef Puppet Chef Coding Style DSL / Ruby DSL Ruby File Server Puppet File Server No Encrypted Data Bag No (*hiera-gpg) Yes Community Puppet Forge Opscode Community Dependencie s Yes No (Code Order) Commercial License / Per Node Hosted Service * http://www.craigdunn.org/2011/10/secret-variables-in-puppet-with-hiera-and-gpg/

Slide 28

Slide 28 text

Vagrant ● VirtualBox, VMware, AWS ● Shell Scripts, Chef, or Puppet ● ihower 2013 OSDC.TW A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩 ○ http://www.slideshare.net/ihower/vagrant-osdc

Slide 29

Slide 29 text

Other Resources ● http://blog.hsatac.net ● http://devops.tw (@devopstw)

Slide 30

Slide 30 text

Q & A