Managing files, directories, and templates
A very useful Chef feature is the ability to manage files right from the Chef code. Either plain files can be copied or dynamic files can be generated through templates. We'll leverage this feature to create an example PHP test file and dynamically generate Apache VirtualHosts for our LAMP server, so you'll know how to reuse it anywhere else.
Getting ready
To work through this recipe, you will need the following:
A working Chef DK installation on the workstation
A working Chef client configuration on the remote host
Optionally, the Chef code from the previous recipes
How to do it…
We'll manage two different kinds of files in two different ways: a static file and a dynamic file generated from a template, so the most common usage is covered.
Managing a simple static file
Let's begin by creating a basic PHP file that will only display the phpinfo()
result. This is done using the simple file
resource with the file path as argument, giving its content inline...