Friday 7 November 2014

Deploying in Azure using Powershell

Deploying in Azure using powershell

This is going to outline how to deploy in Azure using powershell.

Load up Powershell ISE.
Get-AzureAccount to see do i still have my creds there. I do of course. Sweet.

Lets see what images they have to deploy.

Get-AzureVMImage

Whoops - asking me for creds again Add-AzureAccount - enter my creds and we're in again.

Get-AzureVMImage again


I'll be deploying an ubuntu image. I want the newest one (14.04). Lets see what ubuntu ones are there:

Get-AzureVMImage | Where ImageName -Match "Ubuntu" | sort PublishedDate

Theres still loads of results.

Get-AzureVMImage | Where ImageName -Match "Ubuntu-14.04" | sort PublishedDate | Select ImageName -First 1

This brings back one. The latest one. Nice one. So i'll set that as a variable:

$image = Get-AzureVMImage | Where ImageName -Match "Ubuntu-14.04" | sort PublishedDate | Select ImageName -First 1

I'm creating an affinity group. I can script that:

New-AzureAffinityGroup -Name Dublin -Location "North Europe"

And a storage account. I can script that too (make sure the storage account name is all lowercase chars):

New-AzureStorageAccount -StorageAccountName richiesstorageaccount -AffinityGroup Dublin

Need to associate our subscription:

Set-AzureSubscription -SubscriptionName (Get-AzureSubscription).SubscriptionName -CurrentStorageAccountName (Get-AzureStorageAccount -StorageAccountName richiesstorageaccount)

And a new Cloud Service:

New-AzureService -ServiceName richiescloud -AffinityGroup Dublin

I'm creating a variable for some vm options like the size, the user id and password i set on the ubuntu server, and the subnet:

$vm = New-AzureVMConfig -Name richiesubuntu -InstanceSize small | Add-AzureProvisioningConfig -Linux -LinuxUser richie -Password testvm | Set-AzureSubnet -SubnetNames VMNetwork



So i had a couple of issues with the syntax - sorted now though. Successful deployment. Heres the script:

Set-AzureSubscription -SubscriptionName (Get-AzureSubscription).SubscriptionName ` -CurrentStorageAccountName (Get-AzureStorageAccount).Label -PassThru
$image = Get-AzureVMImage | Where ImageName -Match "Ubuntu-14.04" | sort PublishedDate | Select ImageName -First 1
$vm = New-AzureVMConfig -Name richiesubuntu -ImageName $image.ImageName -InstanceSize Small | Add-AzureProvisioningConfig -Linux -LinuxUser richie -Password Testvm01 | Set-AzureSubnet -SubnetNames VMSubnet
New-AzureVM -VMs $vm -ServiceName richiescloud -VNetName RichieNetwork -WaitForBoot



Line 1 = Set the subscription
Line 2 = the image details
Line 3 = the image configuration
Line 4 = the deployment.

Thats me done for tonight.

Tomorrow i'll be scripting a termination, and a bit of capacity reports or something like that from aws. See if i can throw a couple of these scripts together and let the script decide where we need to deploy the servers.

Richie




No comments:

Post a Comment