Zim's Notes

Just work related notes.

Updating Azure Virtual Machine Scale Set Images Using Ansible

This is a new Virtual Machine Scale Set demo I have just released to official Ansible Playbooks for Azure.

I have updated Ansible modules to enable:

  • creating images from existing Azure Virtual Machines
  • updating custom image in Azure Virtual Machine Scale Set

This demo is divided into a few steps. First it demonstrates how to create two custom images (A and B), and we will create VMSS with image A, and finally we will dynamically change image A to image B.

Before trying the playbooks, clone following repository:

1
2
git clone https://github.com/Azure-Samples/ansible-playbooks.git
cd ansible-playbooks/vmss_images

Step One - Create two virtual machines and install HTTPD

Run following playbook:

1
ansible-playbook 01-create-vms.yml --extra-vars "resource_group=myrg"

It will: - create 2 virtual machines - install HTTPD on both of them - change index.html to contain Image A and Image B respectively

Copy and paste IP addresses of both VMs to the browser:

Public IP Address

You should see two different versions of VM:

VM A

and

VM B

Step Two - Capture Images from both Virtual Machines

Run second playbook to capture the images:

1
ansible-playbook 02-capture-images.yml --extra-vars "resource_group=myrg"

Step Three - Create VMSS using Image A

In this step we will create following components: - public IP address - load balancer - VMSS referring image A

Run following playbook:

1
ansible-playbook 03-create-vmss.yml --extra-vars "resource_group=myrg"

Check the IP address printed out at the end:

Public IP Address

check that it works in the browser:

VMSS Image A

Step Four - Update Image Reference in VMSS and Upgrade Instances

Run final playbook to replace image A with image B:

1
ansible-playbook 04-update-vmss-image.yml --extra-vars "resource_group=myrg"

Now press F5 in the browser to reload page and see that image gas changed:

VMSS Image B