Chef: Infrastructure as Code, Automation, Configuration Management, having a service that can do that, and especially having something in place that knows what the desired state of your configurations/applications should be is definitely a plus.
I stumbled upon learn.chef.io which is a great resource for learning chef, as I am learning Chef at this moment.
The Components of Chef consists of:
- Chef Workstation (ChefDK enables you to use the tools locally to test before pushing your code to the Chef Server)
- Chef Server (Central Repository for your Cookbooks and info of every node Chef Manages)
- Chef Client (a Node that is Managed by the Chef Server)
In this post we will install the Chef Development Kit, and work with the chef-client in local-mode to create, update and delete files using the file
resource type.
Getting Started with Chef: Installation:
Installing the Chef Development Kit:
1 2 3 |
|
Configure a Resource:
Using chef-client
in local mode, we will use the resource: file
to create a recipe that will create our motd
file
1 2 3 |
|
Running chef client against our recipe in local-mode:
1 2 3 4 5 6 7 8 9 10 11 |
|
Verify the Content:
1 2 |
|
Running the command again will do nothing, as the content is in its desired state:
1 2 3 4 5 |
|
Changing our recipe by replacing the word world
with chef
, we will find that the content of our file will be updated:
1 2 3 4 5 6 7 8 9 10 11 |
|
Let’s overwrite the content of our motd
file manually:
1
|
|
Running Chef Client against our recipe again, allows Chef to restore our content to the desired state that is specified in our recipe:
1 2 3 4 5 6 7 8 9 10 11 |
|
Deleting a file from our recipe:
1 2 3 |
|
Now using chef client to execute against this file will remove our file:
1 2 3 4 |
|