to continuously define, build, and manage infrastructure. CHEF USES: Recipes and Cookbooks that describe Infrastructure as Code. Chef enables people to easily build & manage complex & dynamic applications at massive scale • New model for describing infrastructure that promotes reuse • Programmatically provision and configure • Reconstruct business from code repository, data backup, and bare metal resources “ ” Chef
[:enable,:start] end template "/etc/ntpd.conf" do source "ntpd.conf.erb" owner "root" group "root" mode 0644 action :create variables(:time_server => “time.example.com”) notifies :restart, “service[ntpd]” end That looks like this
• Have parameters. • Take action to put the resource in the declared state. • Can send notifications to other resources. 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
for opscode: Recipe: (chef-apply cookbook)::(chef-apply recipe) * package[apache2] action install - install version 2.2.22-1ubuntu1 of package apache2 * file[/var/www/index.html] action create - update content in file /var/www/index.html from 94850c to 599510 --- /var/www/index.html 2013-02-24 14:56:23.445076249 +0000 +++ /tmp/chef-diff20130224-3262-1h031ui 2013-02-24 14:56:26.065076250 +0000 @@ -1,4 +1 @@ -<html><body><h1>It works!</h1> -<p>This is the default web page for this server.</p> -<p>The web server software is running but no content has been added, yet.</p> -</body></html> +<h1>Hello, SCALE!</h1> * service[apache2] action start (up to date) * service[apache2] action enable (up to date)
• Download cookbooks from Chef Community Site with Knife. • Extract the cookbook's .tar.gz into cookbooks directory. • Review the code you're going to run as root. • Upload the cookbook to the Chef Server. • Apply the cookbook to your node(s) with a role. • Edit role's run list (base, monitoring) • Modify attributes as required
through sudoers entries. New concepts: • Attribute priority • Setting attributes in Cookbooks and Roles • Using attributes in a template • Ruby array iteration • Package resource • File backups
to the cookbooks directory. • Upload it to the Chef Server. • Add "recipe[sudo]" to the run list. • Modify sudo-specific attributes in the base role. • Run Chef on the target managed node.
user %> ALL=(ALL) <%= "NOPASSWD:" if @passwordless %>ALL <% end -%> # Members of the sysadmin group may gain root privileges %sysadmin ALL=(ALL) <%= "NOPASSWD:" if @passwordless %>ALL <% @sudoers_groups.each do |group| -%> # Members of the group '<%= group %>' may gain root privileges %<%= group %> ALL=(ALL) <%= "NOPASSWD:" if @passwordless %>ALL <% end -%> <%= '#includedir /etc/sudoers.d' if @include_sudoers_d %>
Default backup location is /var/chef/ backup, configurable with "file_backup_path" in /etc/chef/client.rb • 5 backups are kept by default, change this with the "backup" parameter in the resource.
node’s Environment • Create an encrypted data bag item with database credentials • Create a cookbook • Write a file that uses • Search for the host • Encrypted Data Bag for the Credentials