Chef Essentials Training – Day 1

Resources

  • Resource Definition
    <Resource type> <Resource Name>
    <Action>
    <Properties>
    end
  • Install package
    • nano moo.rb
      package ‘cowsay’ do
      action :install
      end
    • sudo chef-client –local-mode moo.rb



  • Create file
  • file ‘/hello.txt’ do
    content ‘Hello World’
    end
  • Default actions need not be explicitly listed for resource. For ‘file’ resource, default action is create.
  • Apply recipe

    sudo chef-client –local-mode hello.rb


  • Default values
  • Update hello.rb
    file ‘/hello.txt’ do
    content ‘Hello World’
    mode ‘0644’
    owner ‘root’
    group ‘root’
    action :create
    end
  • Create new recipe with multiple resources: package (tree) and file (/etc/motd)

    package ‘tree’ do
    action :install
    end

    file ‘/etc/motd’ do
    content ‘Property of tree package’
    end

  • What is resource? Examples?
  • What is Chef-Client?
  • Test and Repair?

Cookbooks

  1. Generate Cookbook
    mkdir cookbooks
    cd cookbooks
    chef generate cookbook workstation


    tree workstation

    Berksfile
    chefignore
    metdata.rb
    Readme.md
    recipes
    default.rb
    spec
    test
  2. Move recipes to new cookbook

    tree workstation

  3. Version Control
    git init in the working directory

    git add .
    git commit –m “Initial Commit ”
    git

Lab: Setting up a Web Server

  1. Create apache cookbook

    chef generate cookbook apache

  2. Create recipe to install apache , create index file and start apache service
    cd apache/recipes/
    nano server.rb
    package ‘httpd’ do
    action :install
    end
    file ‘/var/www/html/index.html’ do
    content ‘<h1>Hello World</h1>’
    end

    service ‘httpd’ do
    action [:enable , :start]
    end

  3. Apply recipe
    sudo chef-client –local-mode server.rb

  4. Curl localhost

Run list

  1. Specify single recipe in run list
    Sudo chef-cleint –local-mode -r “recipe[workstation::setup]”
  2. Run multiple recipes
    Sudo chef-cleint –local-mode -r “recipe[workstation::setup], recipe[apache::server]”
  3. Include recipe in default recipe
    include_recipe ‘workstation::setup’


    Apply cookbook default recipe
    sudo chef-client –local-mode -r “recipe[workstation]”

  4. Include recipes from other cookbooks
    To include recipes from other cookbooks specify dependencies in metadata file. Command ‘depends cookbookname’
    For e.g. if ‘mysql’ cookbook wants to include recipe in ‘apache’ cookbook then update ‘mysql’ metadata file depends apache

Testing Cookbooks

  1. Food critic , Test Kitchen , InStack
  2. Test Kitchen
    To verify cookbooks
    1. Create VM – kitchen create , kitchen.yml driver
    2. Install Chef Tools – kitchen converge, kitchen.yml provisioner
    3. Copy cookbooks – kitchen converge, kitchen.yml provisioner
    4. Run/Apply cookbooks – kitchen converge, kitchen.yml provisioner
    5. Verify assumptions – kitchen verify, kitchen.yml busser
    6. Destroy VM – kitchen destroy
  3. Kitchen.yml


  4. Inspec Testing

  5. Kitchen Create


  6. Kitchen Converge


  7. Kitchen Verify

  8. Kitchen destroy


  9. Kitchen Test


Chef Essentials Training – Day 2
Puppet Enterprise Server
No tags for this post.

Leave a Comment