Konfigurationshantering med Chef




B3 Init

Jonas Linde <jonas.linde@b3.se>

B3 Init AB

[init ab]

Jonas Linde

[me]

Agenda

[lingon]

Bakgrund

Alternativ

[dominoes]

Chef

  • bygger på Chef InSpec och Habitat
[Chef]

Buzz words

Arkitektur

[Client-Server-Controller]

Chef Server

Workstation

Node

Övning

Uppbyggnad

Basbegrepp

chef-repo

Role

{
  "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]"
  ]
}

Environment

{
  "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 bag

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"
}

Cookbook

Recipe

Exempelrecept

$ 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

Några resurser

Resursexempel

package 'tar' do
  version '1.16.1'
  action :install
end

eller

package 'tar' do
  version '1.16.1'
end

eller

package 'tar'

Resursexempel

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

Kedja

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
end

eller

execute 'test-nagios-config' do
  command 'nagios3 --verify-config'
  action :nothing
  subscribes :run, 'template[/etc/nagios3/configures-nagios.conf]', :immediately
end

Attributes

Attributordning

[Chef Attributes]

Template

Exekvering

Grundflöde

Solo

Ad-hoc

Körlista

Sammanfattning

Configuration as Code

Nackdelar

Fördelar

Övningar

Tack för ordet!

[more dominoes]