Contents
Roadmap info from roadmap website
Chef
Emerging in 2009, Chef (now known as Progress Chef) is one of the earliest configuration management tools to gain popularity. Chef βRecipesβ are written in Ruby, in a primarily declarative style. Chef requires that a client is installed on a server being managed. This client polls a Chef-Server regularly, to determine what its configuration should be. Chef-Solo is also available, a version of Chef that allows provisioning of a single node by running chef locally. A key tenet of Chef recipe design is the concept of idempotence. All Chef recipes should be runnable multiple times and produce the same result - this is especially necessary in cases where the client/server model listed above is in use. This pattern of configuration management is highly influential for future declarative tools like Terraform and Cloud Formation.
Visit the following resources to learn more:
Example
Here is an example Chef recipe that creates a Postgres VM:
# File: postgres_vm.rb
# Include the `vm` cookbook to manage virtual machines
include_recipe 'vm'
# Define the VM details
vm_name = 'postgres-vm'
vm_memory = 4096
vm_vcpus = 2
vm_disk_size = 10000
vm_network_interface = 'br0'
# Create the VM
bash 'create_vm' do
code <<-EOF
virt-install --name #{vm_name} --memory #{vm_memory} --vcpus
#{vm_vcpus} --disk size=#{vm_disk_size},format=qcow2 --network
model=virtio,bridge=#{vm_network_interface}
EOF
end
# Install Postgres on the VM
bash 'install_postgres' do
code <<-EOF
ssh #{vm_name}@localhost 'sudo apt-get update && sudo apt-get install
-y postgresql-server'
EOF
end
# Configure Postgres to listen on all interfaces
template '/etc/postgresql/13/main/postgresql.conf' do
source 'postgresql.conf.erb'
variables(
listen_addresses: '*',
port: 5432,
max_connections: 100
)
end
# Restart the Postgres service
service 'postgrsql' do
action [:start, :stop]
end
Let me explain what this recipe does:
-
The first line includes the
vm
cookbook to manage virtual machines. - The next few lines define the VM details: name, memory, vcpus, disk size, and network interface.
-
The
create_vm
bash script creates a new virtual machine usingvirt-install
. -
The
install_postgres
bash script installs Postgres on the VM usingapt-get
. -
The template
/etc/postgresql/13/main/postgresql.conf
configures the Postgres configuration file to listen on all interfaces and sets some basic settings. - Finally, the recipe restarts the Postgres service to apply the new configuration.
Youβll need to create an postgresql.conf.erb
template file with the desired Postgres configuration settings. Hereβs an example:
listen_addresses = <%= @listen_addresses %>
port = <%= @port %>
max_connections = <%= @max_connections %>
This template sets up the Postgres listener to listen on all available network interfaces, sets the port to 5432, and limits the maximum number of connections to 100.
To use this recipe, create a new directory for your cookbook (e.g., postgres_vm
) and add this file (postgres_vm.rb
). Then, run chef-client
in that directory to execute the recipe.