Blog Archives

Writing cookbook on Microsoft Azure

This is the fourth post in the Chef and Microsoft Azure blog series. You can read the previous ones at:


Writing cookbook is similar to how you would write it on other infrastructure. To get started with cookbook on Azure, I am exploring a cookbook to setup apache web server and show home page. Also, this will show you how to upload cookbook to the Chef Server, and set the run list for Chef Node via knife. This blog focus on getting your first cookbook on Azure. This do not go into details of cookbook components, if you would like to learn more about that refer and


  • Microsoft Azure Subscription
  • Have gone through previous three posts in the series

Setup Sequence

  • Create cookbook on workstation
  • Upload cookbook to server
  • Add cookbook to run list of node
  • Run chef-client on node
  • Enable endpoint using Azure CLI

Create cookbook on Workstation

Execute the following commands from the workstation.

# move to home directory


# move to chef-repo directory in home

cd chef-repo

# create new cookbook named webserver

knife cookbook create webserver

Edit the default recipe for webserver and update content of the file to following. vim editor comes default in the instance, so you could use that. To start inserting text in vim, press the ‘i’ key to enter insert mode. When you have finished editing, press ESC to exit insert mode, then type ‘:wq’ to save and exit the editor.

# edit the default recipe

vim cookbooks/webserver/recipes/default.rb

Add index.html file to cookbook’s files/default directory and edit the content.

edit the default index file

vim cookbooks/webserver/files/default/index.html

Upload cookbook to Server

Execute the following commands from the workstation.

# move to home directory


# move to chef-repo directory in home

cd chef-repo

# upload the cookbook to Chef Server

knife cookbook upload webserver

Add cookbook to run list of node

Execute the following commands from the workstation.

# move to home directory


# move to chef-repo directory in home

cd chef-repo

# Add cookbook to the run list of node

knife node run_list add mme-chef-node1 “recipe[webserver]”

Run chef-client on node

Execute the following commands from the Chef Node.

# running chef-client on mme-chef-node1

sudo chef-client

# Ensure that webserver is available on port 80

curl http://localhost/

We have created and executed our first runbook on Azure now. You can learn more about cookbooks from

Enable endpoint using Azure CLI

We have tested and ensured that web server is running and default index file is returned correctly. However, if you try out , the public endpoint 80 of the webserver, you will not get any contents. This is because we only have port 22 in the endpoints of Azure VM. To enable port 80 using Azure CLI, follow the below commands from workstation node.

Login to Azure CLI using your preferred option (Microsoft Account, Organizational Account or Service Principal), following the blog

Once you are logged into Azure CLI, execute the following command to check the current details of the virtual machine. Check endpoint information from the result.

Create new endpoint on port 80. Keep both public port and private port to be 80.

Now we can browse to and see that index page is available.

Next Blog

With this blog, we have gone through the basics of working with Chef on Microsoft Azure. In the next series of blogs, I will dive deep into using Azure specific knife commands and using Chef along with Azure Resource Manager templates.

Setup Chef Node on Microsoft Azure

This is the third post in the Chef and Microsoft Azure blog series. You can read the previous ones at:


These blog posts will help you to learn Chef, by going through all the tutorials provided by Chef – – from Microsoft Azure. In the previous posts, we have gone through the setup of a workstation as well as server. In this post, I am exploring the tutorial

One feedback I received is to automate using script as much as possible, than going through the web user interface. I will try to use scripts to the maximum extent possible.


  • Microsoft Azure Subscription
  • Have gone through previous two posts in this series

Setup Sequence

  • Install Azure CLI & Login
  • Create Virtual Machine for Node
  • Bootstrap & Verify Node

Install Azure CLI and Login

Let us make sure that we have Azure CLI on the workstation server. Execute the following commands from the workstation (We have an Ubuntu 14.04 image for the workstation).


sudo apt-get install nodejs-legacy

sudo apt-get install npm

sudo npm install -g azure-cli

Login to Azure service from CLI. I have written a detailed step by step guidance for the same at If you are looking for complete automation without any user interaction, check out the login option using service principal.

Create Virtual Machine for Node

Next, let us create a new virtual machine to act as the Chef Node. We are executing following commands from the workstation.

# list all azure vm images for Ubuntu 14.04

azure vm image list | grep -i Ubuntu-14_04

# Note that latest image is coming at the end in the list

# Note that image name is second item in the item row

# Get the latest (last) image from the list

imagename=`azure vm image list | grep -i Ubuntu-14_04 |tail -1 | awk ‘{print $2}’`

# Learn about azure vm create options

azure help vm create

# Create a new vm for Chef Node

# vm create [options] <dns-name> <image> [userName] [password]

# SSH port 22 is enabled in endpoints as we use option -e

azure vm create -e -z Small -l “South Central US” mme-chef-node1 $imagename azureuser Demo@Pass1

# Wait for couple of minutes and ensure that Status of vm created is ReadyRole

azure vm list

Bootstrap and Verify Node

From the workstation, execute the bootstrap command remotely to bootstrap the node.

# ensure you are executing these from chef-repo directory


cd chef-repo

# test connection to server, we should see contoso-validator

knife client list

# knife bootstrap ADDRESS -x USER -P PASSWORD –sudo –use-sudo-password –node-name NAME

knife bootstrap -x azureuser -P Demo@Pass1 –sudo –use-sudo-password –node-name mme-chef-node1

# verify that node is successfully bootstrapped

knife node list

Also, you can see the node listed in the Chef Management Portal.

Next Blog

Next, I will try out authoring some basic cookbooks and applying that policy to the node.

Setup Chef Server on Microsoft Azure

This is the second post in the Chef and Microsoft Azure blog series. You can read the first blog in this series at

In this blog, I am exploring how to setup a Chef Server on Microsoft Azure. For most part, I followed the steps suggested in


  • Microsoft Azure Subscription

Setup Sequence

  • Create Virtual Machine
  • Set DNS Name Label for virtual machine
  • Configure Chef Server
  • Create Organization
  • Establish Connectivity from Workstation

Create Virtual Machine

Navigate to and login using your credentials.

Click New, then Compute, then Marketplace

Search for Chef Server, then select Chef Server 12, BYOL.

Note: Chef provides a fully functional Chef server that can be launched from the Azure Marketplace. This server is preconfigured with Chef Server, the Chef Management console, Chef reporting, and Chef Analytics. This configuration is free to use for deployments under 25 nodes, and can be licensed for deployments beyond 25 nodes.

Choose Resource Manager as the deployment model and click Create

Provide basic settings and click OK.

Click Size, then A5 Standard, then Select

Click Settings and then OK. Choose the default options, unless you want to change something.

Click Summary, review summary and click OK

Click Buy on left menu, review offer details and click Buy button

Wait for the newly created server to be in Running state.

Set DNS Name Label for virtual machine

Click Virtual machines, then mme-chef-server

Click on IP Address

Click on Settings, then Configuration

Update DNS name label and click Save

DNS name for the virtual machine in this case is ‘’. Wait for 5 minutes and check if you are able to ssh to the server using ‘ssh

Configure Chef Server

Open Git Bash and run the following commands.

# Here chefadmin is the admin user created during virtual machine creation.

# Provide DNS name label of the virtual machine


#sudo chef-setup -u <username> -p <password> -d <fqdn>

#Here username is a new user, which will be created in this process.

# You will use this username to connect form portal

sudo chef-setup -u admin -p Demo@Pass1 –d

Create Organization


Enter Username (specified during chef-setup), Password (specified during chef-setup) and click Sign In

Click Create New Organization

Provide Full Name, Short Name, then click Create Organization

Click on Administration, then Organizations, then contoso

Click Starter Kit, then Download Starter Kit

Click Proceed

Save locally. In my machine (Windows Laptop), it saved by default in the Downloads folder.

Establish Connectivity from Workstation

Copy the downloaded from local machine to Chef Workstation (I am copying it to workstation, I created as per the first blog in this series). I used the following command to copy the file from Git Bash. You might have to change according to your environment.

scp Downloads/

SSH into workstation


Execute following commands to get SSL keys and test connection to Chef Server

# move to home directory of azureuser


# install unzip utility

sudo apt-get install unzip

# unzip the starter kit


# move to chef-repo directory

cd chef-repo

# retrieve SSL keys from server

knife ssl fetch

# test connection to server, we should see contoso-validator

knife client list

Next Blog

Next, I will try out adding a Chef Node to the organization and running cookbooks.

Setup Chef Workstation on Microsoft Azure

If you do not know how Chef helps with DevOps, I recommend you to watch this conversion, between Matt Stratton, Senior Solutions Architect at Chef and Seth Juarez, Senior Technical Evangelist on the Channel 9 team.

There are lots of tutorials and learning guides available for Chef ( For all my learnings, I completely depend on virtual machines on cloud, unless there is a specific need or limitation to use an on-premise VM. So when I was going through the Chef tutorials, I had to accommodate some changes based on Azure environment. I am documenting my experiments with Chef on Azure in this series of blog posts.


  • Microsoft Azure Subscription
  • Git Bash Shell

Create a Virtual Machine for Chef Workstation

Navigate to on browser

Click on the +NEW link at the bottom-left corner of the screen.


Click UBUNTU, then Ubuntu Server 14.04 LTS, then next arrow

Specify virtual machine configuration and click next. Note that I have used ‘mme-chef-ws’ as the name of virtual machine for Chef Workstation. This name will be used in later steps. Change it according to your environment. Also, for simplicity, I have chosen password option instead of SSH key for the VM.

Change virtual machine configuration if required. Add HTTP endpoint to the endpoints (we enable web server as part of chef learning later), and click next

Click OK

Wait for the created virtual machine to be in running state.

Install Chef Development Kit

The Chef Development Kit (ChefDK) brings the best-of-breed development tools built by the awesome Chef community. Actual download site is However, I have followed steps in another tutorial provided by Chef.

Open Git Bash on your computer and connect to the Chef workstation. Note down the DNS name of virtual machine from the virtual machine details (above picture). Connect to the virtual machine by running the command ‘ssh’

Run the command (curl -L | sudo bash) to install chef client and tools on workstation.

Learn Chef Basics on Ubuntu

Now the workstation is ready for us to learn the basics of Chef. Now we can follow the tutorial provided on Chef learning site on this virtual machine.

Next Blog

Next, I will try out configuring Chef Server and node on Azure.

My views on technology

Virtualization and some coffee

My views on technology

Thomas Maurer

Cloud and Datacenter Blog focusing on Microsoft Azure

Cloud Administrator in Azure World

Begin Your Azure Management Journey with the Cloud Administrator