Manage Azure virtual machine using Chef

 

We already saw how install Chef Server and how configure a Windows Server using Chef. Now, let’s look around the creation of an Azure VM using Chef. Knife-Azure gem provides all you need to handle an Azure account, so let’s install the Knife-Azure gem 🙂

The gem and all the dependencies are now installed. In order to user the Azure API, we need the publishsettings file that contains the certificate to identify you with. In order to get this certificate, open a powershell console and type this

This will open your internet browser with a login webpage to your Microsoft account. Sign in, and select your subscription, you now are prompted by downloading a *.publishsettings file. Download it, and push it to your Chef Server.

Now, edit your knife.rb file to add the path to the publishsettings file. The knife.rb file store your configuration :> (Remember to change the path to your needs)

In order to test if you knife-azure is correctly configured, let’s check if we can list available images for our VMs

You should see a bunch of name with associated regions and the OS type (WIndows or Linux)

 

Create Virtual Machine

Ok now we can start the deployment of our VM.

Now knife is creating our VM…

chef_azure1

Ok your VM is created, but you can’t bootstrap it. Why ? Because WinRM basic authentication isn’t turned ON. So for now we can’t go any further. We’ll see in another post of build how to build you own image in Azure using PowerShell.

If you need to specify more option, you can also check this and see the awesomeness of this knife-azure 🙂

 

Delete Virtual Machine

Before deleting our VM, let’s check how we can list all our Azure VMs, easy just use

chef_azure2

As you can see, we have our VM (and others) here. Remember that you can only see VM in your subsrcipion. If you have multiple Azure subscription file, you can use ‘-p /path/to/yourpublishettingsfile’ !

So, in order to delete your server, this is the command. Note that -y is used to say yes to all prompts for confirmation

chef_azure3

Note that when you delete a server from Azure it is not automatically purged from your Chef Server. In order to do this also, you can use -P option.

For more precision, please use

This is all for today, i hope you liked this post and will be curious enough to push forward the knife-azure gem, do not hesitate to comment if you have any question.