Streamline your infrastructure: Installing Apache2 with Chef

# Cookbook Name:: apache2
# Recipe:: default

# Install Apache package
package 'apache2' do
  action :install
end

# Start Apache service
service 'apache2' do
  action [:enable, :start]
end

# Create default web page
template '/var/www/html/index.html' do
  source 'index.html.erb'
  mode '0644'
  owner 'root'
  group 'root'
end

In this example, the package resource is used to install the Apache2 package, while the service resource is used to start and enable the Apache2 service. The template resource is used to create a custom index.html file at the specified location. The source attribute specifies the location of the template file, and the mode, owner, and group attributes specify the file permissions and ownership.

You can save this code in a cookbook directory, such as /etc/chef/cookbooks/apache2/recipes/default.rb. Then, you can upload the cookbook to the Chef server using the knife command line tool and apply the cookbook to a node using the chef-client command. This will configure the node to have Apache2 installed and running with a default web page.

Leave a Reply

Your email address will not be published. Required fields are marked *