Last post I mentioned that one of our nodes is using a recipe we wrote to install Webmin. We have two nodes running, so we decided to run something different on the second one. We wrote an Apache cookbook to install and configure it. Below is our recipe:
# # Cookbook Name:: apache2 # Recipe:: default # apt_update 'Update the apt cache daily' do frequency 86_400 action :periodic end package 'apache2' service 'apache2' do supports :status => true action [:enable, :start] end file '/var/www/html/index.html' do content '<html> <body> <h1>hello world</h1> </body> </html>' end
It’s pretty simple just like the webmin cookbook. Thankfully I didn’t have to use any bash on this one.
The apt_update package just runs
package’apache2′ is basically the same as running
apt-get install apache2
The service resources simply enables and starts the apache 2 service. The file resource changes the content of index.html to be the html that I posted above.
It’s neat that Chef does all of this stuff automatically. It makes it easy to setup an apache web server really quickly.