Top Banner
35
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: 2015 08-11-scdo-meetup
Page 2: 2015 08-11-scdo-meetup

Ned Harris Solutions Engineer, CHEF

[email protected]

@nedward777

Page 3: 2015 08-11-scdo-meetup

• https://github.com/nedward/socaldevops-realworld

Page 4: 2015 08-11-scdo-meetup

Agenda

•  Overview

•  Chef Software Platform

•  Building Blocks

•  Chef Patterns and Techniques

Page 5: 2015 08-11-scdo-meetup

Overview

•  Chef is an automation framework that enables Infrastructure as Code

•  Chef leverages reusable definitions to automate desired state

•  Chef is API driven

•  Chef supports Linux variants, Unix variants, AIX and Windows, all as first class citizens.

Page 6: 2015 08-11-scdo-meetup

The Chef Software Platform

Chef Analytics Chef Delivery Management console

High availability and replication

Chef Provisioning

Chef Development Kit

Cookbook and policy authoring

Test-driven infrastructure

Containers

Cloud

VMs

Devices

Chef Server Chef Solo

Eco

syst

em

(con

tent

, plu

gins

, etc

.)

Search & Discovery

Chef Success Engineering

Page 7: 2015 08-11-scdo-meetup

Building Blocks

Cookbooks

Recipes

Resources

Page 8: 2015 08-11-scdo-meetup

Building Blocks: What is a Resource?

•  A Resource is a system state you define   Example: Package installed, state of a service, configuration file existing

•  You declare what the state of the resource is   Chef automatically determine HOW that state is achieved

package "httpd" do action :install end

windows_feature "IIS-WebServerRole" do action :install end

Page 9: 2015 08-11-scdo-meetup

Building Blocks: What is a Recipe?

•  A recipe is a collection of Resources •  Resources are executed in the order they are listed

On Linux based OSes:

package "httpd" do action :install end template ”/var/www/index.html" do source ”index.html.erb” mode "0644" end service "httpd" do action [ :enable, :start ] end

windows_feature "IIS-WebServerRole" do action :install end template 'c:\inetpub\wwwroot\Default.htm' do source "Default.htm.erb" rights :read, "Everyone" end service "w3svc" do action [ :enable, :start ] end

Page 10: 2015 08-11-scdo-meetup

Building Blocks: What is a Cookbook?

•  A cookbook is a set of recipes •  A cookbook is a defined set of items

and different outcomes that you expect to address   A cookbook could have a recipe to install

apache2/httpd but also another set of recipes to activate modules required.

./attributes

./attributes/default.rb

./CHANGELOG.md

./metadata.rb

./README.md

./recipes

./recipes/application.rb

./recipes/balancer.rb

./recipes/database.rb

./recipes/default.rb

./recipes/webserver.rb

./templates

./templates/default

./templates/default/mysite.conf.erb

Page 11: 2015 08-11-scdo-meetup

•  Application cookbooks should map 1 to 1 to an application or piece of software

•  Data abstracted from policy, using attributes over hard coded values

A lot of the following patterns assume these tenants are being applied.

Page 12: 2015 08-11-scdo-meetup

Environments

Building Blocks

Roles

Cookbooks

Recipes

Resources

Page 13: 2015 08-11-scdo-meetup

Building Blocks: What is a role?

•  Define reusable roles for Infrastructure Code

chef_type: role default_attributes: my-app: application: version: 1.5.6 description: Role for my application json_class: Chef::Role name: my_application_role run_list: role[base] recipe[my-app::application]

Page 14: 2015 08-11-scdo-meetup

Building Blocks: What is an Environment?

•  Define a reusable environments for Infrastructure Code

chef_type: environment cookbook_versions: database: 2.2.0 default_attributes: myapp: application: version: 1.2.3 description: Our production environment json_class: Chef::Environment name: production

Page 15: 2015 08-11-scdo-meetup

By pinning certain attributes to an environment, you can assure these attributes are global to all nodes within the environment. This allows a single point of control over service configuration to a wide range of servers. You can also pin a cookbook version to an environment, preventing newer versions of that cookbook from being applied to nodes in that environment.

Page 16: 2015 08-11-scdo-meetup
Page 17: 2015 08-11-scdo-meetup

Roles are global in scope, so a change to them can effect any node assigned to that role in any environment. This can lead to unintended consequences.

Pinning attributes to roles.

Page 18: 2015 08-11-scdo-meetup
Page 19: 2015 08-11-scdo-meetup
Page 20: 2015 08-11-scdo-meetup

Because no one organization is the same as another, there is no generic answer to this question.

Page 21: 2015 08-11-scdo-meetup

• What I can do is provide a set of proven patterns and techniques that have been battle tested over time, along with some commonly accepted anti-patterns to avoid.

• By selectively applying these patterns and techniques you can address some of your organization's unique requirements

Page 22: 2015 08-11-scdo-meetup

Note: These patterns are based on tribal knowledge, but not all tribes share the same views. You should look at these patterns objectively based on how they may (or may not) fit for your organization.

Page 23: 2015 08-11-scdo-meetup
Page 24: 2015 08-11-scdo-meetup

Someone has already built 90% of what I want in a community cookbook. It’d be nice to benefit from all that work that has already been done. It’s not 100% the way I need it though.

Page 25: 2015 08-11-scdo-meetup

As its name implies, a wrapper cookbook is one which wraps itself around an existing cookbook, typically an application cookbook. A wrapper cookbook may extend functionality not found in an existing cookbook. In most use cases however it is generally used as a means of changing attributes found in an application cookbook.

Page 26: 2015 08-11-scdo-meetup
Page 27: 2015 08-11-scdo-meetup

This often leads to drift as each version of the cookbook evolves separately. At some point you just own a redundant cookbook, with all the original value of reuse lost.

Copying or forking the application cookbook.

Page 28: 2015 08-11-scdo-meetup

It gets tiring, making sure I’ve added recipes like iptables, dns, ldap etc. to all the different run-lists. I’d like to consolidate all these recipes into a role, but I have been told roles can’t be versioned like cookbooks .

Page 29: 2015 08-11-scdo-meetup
Page 30: 2015 08-11-scdo-meetup

This can lead to an untenable management situation as this base policy evolves over time.

Adding this common base policies ala-cart into many different roles and / or run-lists.

Page 31: 2015 08-11-scdo-meetup

Inside my environment I have a good number of cookbooks that need to be deployed with some variation from one to the next. I’ve been told not to pin attributes to roles though… what do I do?

Page 32: 2015 08-11-scdo-meetup
Page 33: 2015 08-11-scdo-meetup

Roles can apply to all environments within the chef organization. This makes them dangerous. Roles cannot be versioned the way cookbooks can.

Pinning attributes to roles

Page 34: 2015 08-11-scdo-meetup

Thank You – Questions?

Page 35: 2015 08-11-scdo-meetup