Chef Το Chef είναι ένα πλαίσιο αυτοματισμού υποδομής και διαχείρισης ρυθμίσεων γραμμένο σε Ruby και Erlang.
Εγκατάσταση & Standalone Solo
Εγκατάσταση του Chef client σε κόμβους μέσω του επίσημου σεναρίου Omnitruck:
# Εγκατάσταση Chef client
curl -L https://omnitruck.chef.io/install.sh | sudo bash
# Επαλήθευση εγκατάστασης
chef-solo -v
Εκτέλεση αυτόνομου cookbook:
chef-solo -c solo.rb -j node.json
Εντολές Knife CLI
# Αναζήτηση στο μητρώο supermarket
knife supermarket search mysql
# Λήψη αρχείου cookbook
knife supermarket download nginx
# Αρχικοποίηση απομακρυσμένου κόμβου μέσω SSH
knife bootstrap 192.168.1.50 -x root -P 'password' -N web01
Βασικοί πόροι Recipe DSL
Πακέτα & Υπηρεσίες
package 'nginx' do
action :install
end
service 'nginx' do
action [:enable, :start]
supports status: true, restart: true, reload: true
end
Λήψη απομακρυσμένων αρχείων
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
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: εκτέλεση μόνο αν το εκτελέσιμο δεν υπάρχει
end
Συνθήκες 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