Step 7: Update the Cookbook to Create a Directory
Update your cookbook by adding a recipe that adds a directory to the instance. This is similar to running the Linux mkdir command or the Windows md or mkdir commands.
To update the cookbook on the instance and to run the new recipe
On your local workstation, in the
recipessubdirectory in the
opsworks_cookbook_demodirectory, create a file named
create_directory.rbwith the following code. For more information, go to directory:Copy
directory "Create a directory" do group "root" mode "0755" owner "ec2-user" path "/tmp/create-directory-demo" end
At the terminal or command prompt, use the tar command create a new version of the
opsworks_cookbook_demo.tar.gzfile, which contains the
opsworks_cookbook_demodirectory and its updated contents.
Upload the updated
opsworks_cookbook_demo.tar.gzfile to your S3 bucket.
Follow the procedures in Step 5: Update the Cookbook on the Instance and Run the Recipe to update the cookbook on the instance and to run the recipe. In the "To run the recipe" procedure, for Recipes to execute, type
To test the recipe
Log in to the instance, if you have not done so already.
From the command prompt, run the following command to confirm that the new directory was added:Copy
ls -la /tmp/create-directory-demo
Information about the newly-added directory is displayed, including information such as permissions, owner name, and group name:Copy
drwxr-xr-x 2 ec2-user root 4096 Nov 18 00:35 . drwxrwxrwt 6 root root 4096 Nov 24 18:17 ..
In the next step, you will update the cookbook to create a file on the instance.