Snelle referentie

Chef Configuratiebeheer Spiekbrief

Beknopte handleiding voor Chef: knife-CLI, chef-solo, recipe-DSL-bronnen, pakketinstallatie, externe bestanden en voorwaardelijke guards.

· Gepubliceerd

Chef Chef is een framework voor infrastructuurautomatisering en configuratiebeheer geschreven in Ruby en Erlang.

Installatie & Standalone Solo

Installeer Chef-client op doelknooppunten met het officiële Omnitruck-script:

# Chef-client installeren
curl -L https://omnitruck.chef.io/install.sh | sudo bash

# Installatie verifiëren
chef-solo -v

Een standalone cookbook-run uitvoeren:

chef-solo -c solo.rb -j node.json

Knife CLI-commando's

# Zoek in het Supermarket-register
knife supermarket search mysql

# Cookbook-archief downloaden
knife supermarket download nginx

# Een extern knooppunt via SSH bootstrappen
knife bootstrap 192.168.1.50 -x root -P 'password' -N web01

Belangrijke Recipe-DSL-bronnen

Pakketten & Services

package 'nginx' do
  action :install
end

service 'nginx' do
  action [:enable, :start]
  supports status: true, restart: true, reload: true
end

Externe bestandsdownloads

remote_file '/usr/local/src/node.tar.gz' do
  source 'https://nodejs.org/dist/v18.0.0/node-v18.0.0.tar.gz'
  checksum 'sha256checksumhere...'
  mode '0644'
  action :create_if_missing
end

Shell-commando's uitvoeren

execute 'compile_app' do
  command './configure && make && make install'
  cwd '/usr/local/src/app'
  environment 'PATH' => "/usr/local/bin:#{ENV['PATH']}"
  creates '/usr/local/bin/app' # Guard: alleen uitvoeren als bestand niet bestaat
end

Voorwaardelijke guards (only_if & not_if)

execute 'migrate_database' do
  command 'rails db:migrate'
  cwd '/var/www/app/current'
  only_if { File.exist?('/var/www/app/current/Rakefile') }
  not_if  'pg_isready -h localhost'
end

Verwante onderwerpen