Week2 Nodeandcookbook 140527115111 Phpapp01

download Week2 Nodeandcookbook 140527115111 Phpapp01

of 87

Transcript of Week2 Nodeandcookbook 140527115111 Phpapp01

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    1/87

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    2/87

    Community Director

    Co-host of the Food Fight Show Podcast

    @nathenharvey

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    3/87

    3

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    4/87

    After completing of this webinar series you will beable to

    Automate common infrastructure tasks with Chef Describe Chefs architecture

    Describe Chefs various tools

    Apply Chefs primitives to solve your problems

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    5/87

    You bring the domain expertise about your businessand infrastructure

    Chef provides a framework for automating yourinfrastructure

    Our job is to work together to teach you how tomodel and automate your infrastructure with Chef

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    6/87

    Learning Chef is like learning the basics of alanguage

    80% fluency will be reached very quickly The remaining 20% just takes practice

    The best way to learnChef is to useChef

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    7/87

    Ask questions in the chatwindow when they come toyou

    Well answer as manyquestions as we can at theend of the session

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    8/87

    This webinar is being recorded. The video will bemade available shortly after the session has ended.

    The slides used throughout this webinar will bemade available at the end of each webinar.

    Watch http://learnchef.com for updates.

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    9/87

    9

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    10/87

    Overview of Chef

    Workstation Setup

    Node Setup - Today Chef Resources and Recipes - Today

    Working with the Node object

    Common configuration with Data Bags

    Roles and Environments

    Community Cookbooks and Further Resources

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    11/87

    11

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    12/87

    After completing the lesson, you will be able to

    Login to the node in your Chef Training Lab

    Install Chef nodes using "knife bootstrap" Explain how knife bootstrap configures a node to

    use the Organization created in the previoussection

    Explain the basic configuration needed to run chef-client

    12

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    13/87

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    14/87

    14

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    15/87

    15

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    16/87

    Nodes represent the servers in your infrastructurethese may be

    Physical or virtual servers Hardware that you own

    Compute instances in a public or private cloud

    16

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    17/87

    17

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    18/87

    $ ssh root@

    The authenticity of host 'uvo1qrwls0jdgs3blvt.vm.cld.sr(69.195.232.110)' can't be established.

    RSA key fingerprint is d9:95:a3:b9:02:27:e9:cd:

    74:e4:a2:34:23:f5:a6:8b.

    Are you sure you want to continue connecting (yes/no)? yes

    Warning: Permanently added 'uvo1qrwls0jdgs3blvt.vm.cld.sr,

    69.195.232.110' (RSA) to the list of known hosts.

    [email protected]'s password:Last login: Mon Jan 6 16:26:24 2014 from

    host86-145-117-53.range86-145.btcentralplus.com

    [chef@CentOS63 ~]$

    18

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    19/87

    At this point you should have

    One virtual machine (VM) or server that youll use

    for the lab exercises The IP address or public hostname

    An application for establishing an ssh connection

    'sudo' or 'root' permissions on the VM

    19

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    20/87

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    21/87

    $ knife bootstrap -x chef-P chef-N "module2"

    Bootstrapping Chef on uvo1qrwls0jdgs3blvt.vm.cld.sr......uvo1qrwls0jdgs3blvt.vm.cld.sr Creating a new client identity for

    module2 using the validator key.uvo1qrwls0jdgs3blvt.vm.cld.sr resolving cookbooks for run list: []uvo1qrwls0jdgs3blvt.vm.cld.sr Synchronizing Cookbooks:

    uvo1qrwls0jdgs3blvt.vm.cld.sr Compiling Cookbooks...uvo1qrwls0jdgs3blvt.vm.cld.sr [2014-01-28T11:03:14-05:00] WARN: Nodenode2 has an empty run list.uvo1qrwls0jdgs3blvt.vm.cld.sr Converging 0 resourcesuvo1qrwls0jdgs3blvt.vm.cld.sr Chef Client finished, 0 resources updated

    21

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    22/87

    Node

    22

    WorkstationChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    23/87

    Node

    23

    Workstation

    knife bootstrap HOSTNAME -x root -P PASSWORD -N module2

    ChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    24/87

    Node

    24

    Workstation

    knife bootstrap HOSTNAME -x root -P PASSWORD -N module2

    ssh/scp

    chef_server_urlvalidation_client_namevalidation_client_key

    ChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    25/87

    Node

    25

    Workstation

    knife bootstrap HOSTNAME -x root -P PASSWORD -N module2

    ssh/scp

    chef_server_urlvalidation_client_namevalidation_client_key

    install chef-clientconfigure chef-client

    run chef-client

    ChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    26/87

    Node

    26

    Workstation

    knife bootstrap HOSTNAME -x root -P PASSWORD -N module2

    ssh/scp

    chef_server_urlvalidation_client_namevalidation_client_key

    register nodesave node details

    install chef-clientconfigure chef-client

    run chef-client

    ChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    27/87

    Node

    27

    Workstation

    knife bootstrap HOSTNAME -x root -P PASSWORD -N module2

    ssh/scp

    chef_server_urlvalidation_client_namevalidation_client_key

    register nodesave node details

    install chef-clientconfigure chef-client

    run chef-client

    ChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    28/87

    Node

    28

    Workstation

    knife bootstrap HOSTNAME -x root -P PASSWORD -N module2

    ssh/scp

    chef_server_urlvalidation_client_namevalidation_client_key

    register nodesave node details

    install chef-clientconfigure chef-client

    run chef-client

    ChefServer

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    29/87

    $ ssh root@

    root@CentOS63:~$ls /etc/chefclient.pem client.rb first-boot.json validation.pem

    root@CentOS63:~$which chef-client

    /usr/bin/chef-client

    29

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    30/87

    Click the 'Details' tab

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    31/87

    31

    Click the 'Attributes' tab

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    32/87

    The node is registered with Chef Server

    The Chef Server displays information about the node

    This information comes from Ohai - we'll see Ohailater.....

    32

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    33/87

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    34/87

    34

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    35/87

    After completing the lesson, you will be able to

    Describe in detail what a cookbookis

    Create a new cookbook

    Explain what a recipeis

    Describe how to use the package, service, and templateresources

    Upload a cookbookto the Chef Server

    Explain what a run list is, and how to set it for a node viaknife

    Explain the output of a chef-client run35

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    36/87

    A cookbook is like a package for Chef recipes.

    It contains all the recipes, files, templates, libraries,etc. required to configure a portion of yourinfrastructure

    Typically they map 1:1 to a piece of software orfunctionality.

    36

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    37/87

    The Problem:We need a web server configured toserve up our home page.

    Success Criteria:We can see the homepage in aweb browser.

    37

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    38/87

    Apache web server should be installed

    Apache should be running and configured to start whenthe machine boots

    Our home page should be displayed

    Please note in this course we're teaching Chef

    primitives, not web server management This is probably not the Apache HTTP server

    configuration you would use in production38

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    39/87

    $ knife cookbook create apache

    ** Creating cookbook apache

    ** Creating README for cookbook: apache

    ** Creating CHANGELOG for cookbook: apache

    ** Creating metadata for cookbook: apache

    39

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    40/87

    $ ls -la cookbooks/apache

    total 24

    drwxr-xr-x 13 opscode opscode 442 Jan 24 21:25 .drwxr-xr-x 5 opscode opscode 170 Jan 24 21:25 ..

    -rw-r--r-- 1 opscode opscode 412 Jan 24 21:25 CHANGELOG.md-rw-r--r-- 1 opscode opscode 1447 Jan 24 21:25 README.md

    drwxr-xr-x 2 opscode opscode 68 Jan 24 21:25 attributesdrwxr-xr-x 2 opscode opscode 68 Jan 24 21:25 definitions

    drwxr-xr-x 3 opscode opscode 102 Jan 24 21:25 files

    drwxr-xr-x 2 opscode opscode 68 Jan 24 21:25 libraries-rw-r--r-- 1 opscode opscode 276 Jan 24 21:25 metadata.rb

    drwxr-xr-x 2 opscode opscode 68 Jan 24 21:25 providers

    drwxr-xr-x 3 opscode opscode 102 Jan 24 21:25 recipesdrwxr-xr-x 2 opscode opscode 68 Jan 24 21:25 resources

    drwxr-xr-x 3 opscode opscode 102 Jan 24 21:25 templates

    40

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    41/87

    If you're using Sublime, then File>Open the chef-repodirectory you created earlier

    41

    Access thecookbook filesfrom the leftmenu

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    42/87

    OPEN IN EDITOR: cookbooks/apache/recipes/default.rb

    #

    # Cookbook Name:: apache

    # Recipe:: default#

    # Copyright 2013, YOUR_COMPANY_NAME

    #

    # All rights reserved - Do Not Redistribute

    #

    42

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    43/87

    SAVE FILE!

    #

    # Cookbook Name:: apache

    # Recipe:: default

    ## Copyright 2013, YOUR_COMPANY_NAME

    #

    # All rights reserved - Do Not Redistribute

    #

    package "httpd"do action :install

    end

    OPEN IN EDITOR: cookbooks/apache/recipes/default.rb

    43

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    44/87

    package "httpd"do

    action :install

    end

    44

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    45/87

    package "httpd"do

    action :install

    end

    Is a packageresource

    45

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    46/87

    package "httpd"do

    action :install

    end

    Is a package resource

    Whose nameis httpd

    46

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    47/87

    package "httpd"do

    action :install

    end

    Is a package resource

    Whose name is httpd

    With an install action

    47

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    48/87

    Resources are declarative- that means we say whatwe want to have happen, rather than how

    Resources take action through Providers- providersperform the how

    Chef uses the platformthe node is running to

    determine the correct providerfor a resource

    48

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    49/87

    package "git"{

    yum install git

    apt-get install git

    pacman sync git

    pkg_add -r git

    Providersaredetermined

    bynode'splatform

    49

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    50/87

    SAVE FILE!

    ...

    # All rights reserved - Do Not Redistribute

    #

    package "httpd"do

    action :install

    end

    service "httpd"do action [:enable, :start]

    end

    OPEN IN EDITOR: cookbooks/apache/recipes/default.rb

    50

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    51/87

    service "httpd"do

    action [:enable, :start]

    end

    51

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    52/87

    service "httpd"do

    action [:enable, :start]

    end

    Is a serviceresource

    52

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    53/87

    service "httpd"do

    action [:enable, :start]

    end

    Is a service resource

    Whose nameis httpd

    53

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    54/87

    service "httpd"do

    action [:enable, :start]

    end

    Is a service resource

    Whose nameis httpd

    With two actions: enable

    start

    54

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    55/87

    Body Level One

    Body Level Two

    Body Level Three Body Level Four

    Body Level Five

    package "haproxy"do

    action :install

    end

    template "/etc/haproxy/haproxy.cfg"do

    source "haproxy.cfg.erb"

    owner "root"

    group "root"

    mode "0644"

    notifies :restart, "service[haproxy]"

    end

    service "haproxy"do supports :restart=>:true

    action [:enable, :start]

    end

    Resources areexecuted in order

    1st

    2nd

    3rd

    55

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    56/87

    SAVE FILE!

    ...

    service "httpd"do

    action [:enable, :start]

    end

    template "/var/www/html/index.html"do

    source "index.html.erb"

    mode "0644"

    end

    OPEN IN EDITOR: cookbooks/apache/recipes/default.rb

    56

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    57/87

    template "/var/www/html/index.html"do

    source "index.html.erb"

    mode "0644"

    end

    57

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    58/87

    Is a templateresource

    template "/var/www/html/index.html"do

    source "index.html.erb"

    mode "0644"

    end

    58

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    59/87

    Is a template resource

    Whose nameis:/var/www/html/index.html

    template "/var/www/html/index.html"do

    source "index.html.erb"

    mode "0644"

    end

    59

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    60/87

    Is a template resource

    Whose nameis:/var/www/html/index.html

    With two parameters:

    sourceofindex.html.erb

    mode of 0644

    template "/var/www/html/index.html"do

    source "index.html.erb"

    mode "0644"

    end

    60

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    61/87

    #

    # Cookbook Name:: apache

    # Recipe:: default

    #

    # Copyright 2013, YOUR_COMPANY_NAME

    #

    # All rights reserved - Do Not Redistribute

    #

    package "httpd"do

    action :install

    end

    service "httpd"do action [:enable, :start]

    end

    template "/var/www/html/index.html"do source "index.html.erb"

    mode "0644"

    end

    61

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    62/87

    OPEN IN EDITOR:

    SAVE FILE!

    cookbooks/apache/templates/default/index.html.erb

    Hello, world!

    62

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    63/87

    $ knife cookbook upload apache

    Uploading apache [0.1.0]

    Uploaded 1 cookbook.

    63

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    64/87

    knife cookbook upload apache

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    65/87

    knife cookbook upload apache

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    66/87

    knife cookbook upload apache

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    67/87

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    68/87

    The Run List is the ordered set of recipes and rolesthat the Chef Client will execute on a node

    Recipes are specified by recipe[name]

    68

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    69/87

    $ knife node run_list add module2 "recipe[apache]"

    module2:

    run_list: recipe[apache]

    69

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    70/87

    knife node run_list add module2 recipe[apache]

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    71/87

    knife node run_list add module2 recipe[apache]

    recipe[apache]

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    72/87

    knife node run_list add module2 recipe[apache]

    recipe[apache]

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    73/87

    knife node run_list add module2 recipe[apache]

    recipe[apache]

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    74/87

    knife node run_list add module2 recipe[apache]

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    75/87

    root@CentOS63:~$ sudo chef-client

    Starting Chef Client, version 11.10.4

    resolving cookbooks for run list: ["apache"]

    Synchronizing Cookbooks:

    - apacheCompiling Cookbooks...

    Converging 3 resources

    Recipe: apache::default

    * package[httpd] action install

    - install version 2.2.15-29.el6.centos of package httpd

    * service[httpd] action enable

    - enable service service[httpd]

    * service[httpd] action start

    - start service service[httpd]

    * template[/var/www/html/index.html] action create

    - create new file /var/www/html/index.html

    - update content in file /var/www/html/index.html from none to 17d291

    75

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    76/87

    Open a web browser

    Type in the the URL for your test node

    76

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    77/87

    You have just written your first Chef cookbook!

    (clap!)

    77

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    78/87

    Node

    Enterprise

    Chefchef-client

    WhatpolicyshouldIfollow?

    78

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    79/87

    Node

    Enterprise

    Chefchef-client

    WhatpolicyshouldIfollow?

    "recipe[apache]"

    79

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    80/87

    Node

    Enterprise

    Chefchef-client

    WhatpolicyshouldIfollow?

    "recipe[apache]"

    80

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    81/87

    Enterprise

    Chefchef-client

    WhatpolicyshouldIfollow?

    "recipe[apache]"

    81

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    82/87

    Enterprise

    Chefchef-client

    WhatpolicyshouldIfollow?

    "recipe[apache]"

    82

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    83/87

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    84/87

    Module 1 - Overview of Chef

    Today - Node Setup, Chef Resources & Recipes

    June 3 - Working with the Node object

    June 10 - Common configuration data with Databags

    June 17 - Using Roles and Environments

    June 24 - Community Cookbooks and Further Resources

    * Topics subject to change, schedule unlikely to change

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    85/87

    http://pages.getchef.com/cheffundamentalsseries.html

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    86/87

    Chef Fundamentals Webinar Series

    https://www.youtube.com/watch?v=S5lHUpzoCYo&list=PL11cZfNdwNyPnZA9D1MbVqldGuOWqbumZ

    Discussion group for webinar participants

    https://groups.google.com/d/forum/learnchef-fundamentals-webinar

    102

  • 7/23/2019 Week2 Nodeandcookbook 140527115111 Phpapp01

    87/87

    Learn Chef

    http://learnchef.com

    Documentationhttp://docs.opscode.com

    103