Top Banner
Chef Fundamentals
44

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

May 07, 2015

Download

Business

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Chef Fundamentals

Page 2: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Chef Client Run and Expanding Our CookbookChef Fundamentals Webinar Series - Module 4

[email protected]

Page 3: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Nathen Harvey• Technical Community Manager at Opscode• Co-host of the Food Fight Show Podcast

• @nathenharvey

[email protected]

Page 4: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Quick Recap

Page 5: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Checkpoint• In the last module we

• bootstrapped a node using knife bootstrap• wrote a simple cookbook to deploy a simple

webpage

Page 6: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Where'd my Node go?• You still need an Ubuntu 10.04+ machine to manage

• Launch a new instance in the training lab• Fire up a new Vagrant• Launch an new AMI Instance

Page 7: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

But it might not have worked• In some instances, the apt-cache was out of date• You can fix this!

• sudo apt-get update

Page 8: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Fix it the Chef way!• Create an apt cookboook• Use an execute resource• Add to the run list

Page 9: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Dissecting your first chef-client runThe Anatomy of a Chef run

Page 10: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Objectives• Describe the steps of a chef-client run• Describe the basic security model of Chef

Page 11: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

chef-client

Page 12: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build nodechef-client

Page 13: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build nodechef-client

Ohai!node_name

platformplatform_version

Page 14: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticatechef-client

Page 15: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

chef-client

expanded run list(recipes)

Page 16: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

load cookbooks

chef-client

Page 17: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

load cookbooks

converge

chef-client

Page 18: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

load cookbooks

converge

chef-client

success?

Page 19: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

load cookbooks

converge

node.saveYes

chef-client

success?

Page 20: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

load cookbooks

converge

node.save

exception

Yes

No

chef-client

success?

Page 21: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

build node authenticate

sync cookbooks

load cookbooks

converge

node.savenotificationhandlers

exception

Yes

No

chef-client

success?

Page 22: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Private Keys• Chef Server requires keys to authenticate.

• client.pem - private key for API client• validation.pem - private key for ORGNAME-

validator• Next, let’s see how those are used...

Page 23: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

Page 24: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

Sign Requests

Yes

Page 25: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

/etc/chef/validation.pem?

Sign Requests

Yes

No

Page 26: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

/etc/chef/validation.pem? 401!

Sign Requests

Yes

No No

Page 27: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

/etc/chef/validation.pem? 401!

Request API Client

Sign Requests

Yes

No No

Yes

Page 28: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

/etc/chef/validation.pem? 401!

Request API Client

Sign Requests client.pem

Yes

No No

Yes

Page 29: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

/etc/chef/client.pem?

/etc/chef/validation.pem? 401!

Request API Client

Sign Requests client.pem

Yes

No No

Yes

Page 30: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Compile and Execute• Compile a Resource Collection• Execute the Resources in that Collection

Page 31: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Introducing the Node objectAttributes & Search

Page 32: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Lesson Objectives• After completing the lesson, you will be able to

• Explain what the Node object represents in Chef• List the Nodes in an organization• Show details about a Node• Describe what Node Attributes are• Retrieve a node attribute directly, and via search

Page 33: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

What is the Node object• A node is any physical, virtual, or cloud machines

that is configured to be maintained by a Chef • When you are writing Recipes, the Node object is

always available to you.

Page 34: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife node list

Exercise: List nodes

target1

Page 35: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife client list

Exercise: List clients

ORGNAME-validatortarget1

Page 36: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Each node must have a unique name• Every node must have a unique name within an

organization• Chef defaults to the Fully Qualified Domain Name of

the server, i.e. in the format server.domain.com• We overrode it to "target1" to make typing easier

Page 37: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife node show target1

Exercise: Show node details

Node Name: target1Environment: _defaultFQDN: ip-10-154-155-107.ec2.internalIP: 54.242.35.165Run List:Roles:Recipes:Platform: ubuntu 12.04Tags:

Page 38: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

What is the Node object• Nodes are made up of Attributes

• Many are discovered automatically (platform, ip address, number of CPUs)

• Many other objects in Chef can also add Node attributes (Cookbooks, Roles and Environments, Recipes, Attribute Files)

• Nodes are stored and indexed on the Chef Server

Page 39: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

opscode@target1:~$ sudo ohai | less

Exercise: Run Ohai on node

{ "languages": { "ruby": {

}, "python": { "version": "2.7.3", "builddate": "Apr 10 2013, 06:20:15" }, "perl": { "version": "5.14.2", "archname": "x86_64-linux-gnu-thread-multi" } }, "kernel": {

Page 40: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife node show target1 -l

Exercise: Show all the node attributes

Node Name: target1Environment: _defaultFQDN: ip-10-154-155-107.ec2.internalIP: 54.242.35.165Run List:Roles:Recipes:Platform: ubuntu 12.04Tags:Attributes:tags:

Default Attributes:

Override Attributes:

Automatic Attributes (Ohai Data):block_device: loop0: removable: 0 size: 0

Page 41: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife node show target1 -Fj

Exercise: Show the raw node object

{ "name": "target1", "chef_environment": "_default", "run_list": [], "normal": {"tags":[]}}

Page 42: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife node show target1 -a fqdn

Exercise: Show only the fqdn attribute

target1: fqdn: ip-10-154-155-107.ec2.internal

Page 43: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

$ knife search node "*:*" -a fqdn

Exercise: Use search to find the same data

1 items found

target1: fqdn: ip-10-154-155-107.ec2.internal

Page 44: Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding Our Cookbook

Templates and Cross-platformRevisit the Apache Cookbook