We’ve seen how we can create and upload packages to our chocolatey repository in the previous posts. Next we’ll use this source and install packages from a configuration management tool like Chef or DSC to automatically install and manage packages on the infrastructure. This post, I’ll explain how to install Chocolatey on the infrastructure that in managed in Chef and later we’ll see how we use chocolatey to install packages on the infrastructure.
The chef community has a lot of cookbooks contributed that can be used for most of the work we need. You can find cookbooks that are available on chef supermarket at this link https://supermarket.chef.io/.
To access and install these cookbooks on your workstation and later upload to the chef server, we’ll use the knife commands. Before using the commands, we need to initialize a Git repository at the cookbook location. You can download and install Git from the url https://msysgit.github.io/.
Follow the default instructions and during the path setup dialog, choose the option to use the integrate with windows command prompt option as given below.
Next create a Git repository in GitHub as given below.
Initialize the Git repository at the cookbooks folder under the chef-repo folder in your workstation using Github for windows or using the Git init command. I’ve used the GitHub for windows tool to create and initialize a repository as given below.
Do a commit on the master branch from the command prompt or publish from the GitHub tool
Next we’ll download the chocolatey cookbook from the community cookbooks url. The chocolate cookbook is dependent on the windows and chef_handler cookbook. So before using the chocolatey cookbook you need to resolve the dependencies cookbook.
Use the knife cookbook site install command to install the cookbooks from the supermarket to the workstation.
For e.g to install the chocolatey cookbook use the command like given below.
You need to install the dependent cookbooks also using the same approach. After installing the cookbooks your workstation should look like.
After installing the cookbooks you can publish the branch to Git using the commit command or from the GitHub tool.
Next we can upload the cookbooks to the chef server using the knife cookbook upload command.
Upload the cookbooks in the order given below.
Now we can start using these cookbooks on a node that is registered to the chef server.
For this sample, I’ve created a role chocolateydemovm as given below for the demonstration and used the recipes from the cookbooks uploaded as the run list.
Next assign this role the node as in the screenshot
That’s all, you can see during the next run, chef will install chocolatey on the infrastructure and manage it.
Next we’ll use the chocolatey cookbook and install some packages from our source created in the post following.