And our full webserver.rb recipe will look like the following:
1234567891011121314151617181920212223
# update cache periodically every 24 hoursapt_update'Update APT Cache Daily'dofrequency86_400action:periodicend# install apache2 (:install is the default action)package'apache2'# enable apache2 on boot and start apache2service'apache2'dosupportsstatus:trueaction[:enable,:start]end# create a custom html pagefile'/var/www/html/index.html'docontent'<html> <body> <h1>Hello, World!</h1> </body></html>'end
Running our Chef Client against our Recipe:
For the previous snippets, we took it section by section, here we will run the whole recipe:
123456789101112
$ chef-client --local-mode webserver.rb
...
Converging 4 resources
Recipe: @recipe_files::/root/chef-repo/webserver.rb
* apt_update[Update APT Cache Daily] action periodic (up to date) * apt_package[apache2] action install (up to date) * service[apache2] action enable(up to date) * service[apache2] action start (up to date) * file[/var/www/html/index.html] action create
- update content in file /var/www/html/index.html from 538f31 to 9d1dca
--- /var/www/html/index.html 2017-09-04 16:53:55.134043652 +0000
+++ /var/www/html/.chef-index20170904-7451-3kt1p7.html 2017-09-04 17:00:16.306831840 +0000