![[init ab]](img/b3-tagline.png) 
![[me]](img/mii.png) 
![[lingon]](img/lingon.png) 
![[dominoes]](img/dominoes.png) 
- bygger på Chef InSpec och Habitat
Hanterar servern
Använder knife för att kommunicera med servern och noderna
Kan använda chef-run för att köra ad-hoc på noder
chef-workstation är ett paket att ladda ner från https://chef.io/downloads
chefdk är ett liknande paket byggt av communityn
Med knife kan man även hämta community-skrivna kokböcker
knife supermarket search apt knife supermarket download aptly
{
  "chef_type": "role",
  "json_class": "Chef::Role",
  "name": "webserver",
  "description": "The base role for systems that serve HTTP traffic",
  "default_attributes": {
    "apache2": {
      "listen_ports": [
        "80"
      ]
    }
  },
  "run_list": [
    "recipe[apache2]",
    "recipe[apache2::mod_ssl]",
    "role[monitor]"
  ]
}
{
  "chef_type": "environment",
  "json_class": "Chef::Environment",
  "name": "dev",
  "description": "Dev Environment",
  "default_attributes": {
    "apache2": {
      "listen_ports": [
        "80"
      ]
    }
  },
  "cookbook_versions": {
    "couchdb": "= 11.0.0"
  }
}
data_bags/
  sample_bag_1/
    sample_item_1_1.json
    sample_item_1_2.json
    sample_item_1_3.json
  sample_bag_2/
    sample_item_2_1.json
    sample_item_2_2.json
{
  // This is a comment
  "id": "ITEM_NAME",
  "anykey": "anyvalue"
}
$ cat webserver/recipes/default.rb # # Cookbook:: webserver # Recipe:: default # # Copyright:: 2018, The Authors, All Rights Reserved. apt_update package 'apache2' template '/var/www/html/index.html' do source 'index.html.erb' end service 'apache2' do action [:enable, :start] end
package 'tar' do version '1.16.1' action :install endeller
package 'tar' do version '1.16.1' endeller
package 'tar'
bash 'extract_module' do
  cwd ::File.dirname(src_filepath)
  code <<-EOH
    mkdir -p #{extract_path}
    tar xzf #{src_filename} -C #{extract_path}
    mv #{extract_path}/*/* #{extract_path}/
    EOH
  not_if { ::File.exist?(extract_path) }
end
execute 'test-nagios-config' do command 'nagios3 --verify-config' action :nothing end template '/etc/nagios3/configures-nagios.conf' do # other parameters notifies :run, 'execute[test-nagios-config]', :delayed endeller
execute 'test-nagios-config' do command 'nagios3 --verify-config' action :nothing subscribes :run, 'template[/etc/nagios3/configures-nagios.conf]', :immediately end
Kommer från
Exempel:
$ cat cookbooks/starter/attributes/default.rb default["starter_name"] = "Sam Doe" override["system_name"] = "Chef Starter"
Läs mer: https://docs.chef.io/attributes.html
![[Chef Attributes]](img/chef_attributes_table.png) 
Exempel:
$ cat webserver/templates/index.html.erb
<html>
  <head>
    <title>Learn Chef Demo</title>
  </head>
  <body>
    <h1>Hello Learn Chef</h1>
    <p>This is <%=node['hostname']%></p>
  </body>
</html>
Listan av recept som ska exekveras kan anges
på kommandoraden:
chef-client --runlist "apache2,recipe[apache2::mod_ssl],role[webserver]"
på kommandoraden i cron
i en roll:
"run_list": [ "recipe[apache2]", "recipe[apache2::mod_ssl]", "role[webserver]" ]
Om ingen run_list anges, används senaste lyckade exekvering
![[more dominoes]](img/dominoes2.jpg) 
