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 🙂
sudo gem install knife-azure
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)
knife[:azure_publish_settings_file] = "/home/fabien/chef-repo/Azure/demo_2015.publishsettings"
In order to test if you knife-azure is correctly configured, let’s check if we can list available images for our VMs
knife azure image list
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.
knife azure server create --azure-dns-name "srvdemochef" \ --azure-service-location "East US" \ --azure-source-image a699494373c04fc0bc8f2bb1389d6106__Win2K8R2SP1-Datacenter-201502.01-en.us-127GB.vhd \ --winrm-user 'fabien' --winrm-password '<password>' \ --distro 'windows-chef-client-msi'
Now knife is creating our VM…
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 🙂
knife azure server create --help
Delete Virtual Machine
Before deleting our VM, let’s check how we can list all our Azure VMs, easy just use
knife azure server list
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
knife azure server delete srvdemochef -y
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
knife azure server delete --help
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.