Kurzreferenz

Chef Konfigurationsmanagement Spickzettel

Kurzreferenz für Chef: knife-CLI, chef-solo, Recipe-DSL-Ressourcen, Paketinstallation, Remote-Dateien und bedingte Guards.

· Veröffentlicht

Chef Chef ist ein Framework zur Automatisierung von Infrastruktur und Konfigurationsmanagement, geschrieben in Ruby und Erlang.

Installation & Standalone Solo

Chef-Client auf Zielknoten mit dem offiziellen Omnitruck-Skript installieren:

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

# Installation überprüfen
chef-solo -v

Einen eigenständigen Cookbook-Lauf ausführen:

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

Knife CLI-Befehle

# Supermarket-Registry durchsuchen
knife supermarket search mysql

# Cookbook-Archiv herunterladen
knife supermarket download nginx

# Einen Remote-Knoten via SSH bootstrappen
knife bootstrap 192.168.1.50 -x root -P 'password' -N web01

Wichtige Recipe-DSL-Ressourcen

Pakete & Dienste

package 'nginx' do
  action :install
end

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

Remote-Dateien herunterladen

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-Befehle ausführen

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: Nur ausführen, wenn Binärdatei noch nicht existiert
end

Bedingte 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

Verwandte Themen