Projects

Microsoft Azure: create resources using Ansible

Using this walkthrough, I use Ansible to create resources in my Microsoft Azure account. I then use Ansible to create a virtual machine within that environment. I’m running Ansible on my localhost within the Windows Subsystem for Linux. This page gives an outline and then showcases parts of this project. You can find the Ansible files used in this project here.

  1. Create a resource group
  2. Create a virtual network
    • Create a subnet within the virtual network
  3. Create a public IP address
  4. Create a network security group
  5. Create a virtual network interface card
  6. Create a storage account
  7. Create a virtual machine
  8. Interactively SSH into the virtual machine using Azure Cloud Shell
  9. Deallocate virtual machine

The following excerpts are shown below:

  1. The entire contents of the file that creates a network security group
  2. Interactive SSH session with the virtual machine
  3. Details about the virtual machine as seen in the Azure portal
---

# creates a network security group in Azure

- hosts: localhost
  connection: local
  tasks:
    - name: Create Network Security Group - {{ name }} in Resource Group - {{ ResourceGroup }} that allows SSH
      azure_rm_securitygroup:
        resource_group: "{{ ResourceGroup }}"
        name: "{{ name }}"
        rules:
          - name: SSH
            description: Allow SSH traffic on TCP port 22
            protocol: Tcp
            destination_port_range: 22
            access: Allow
            priority: 1001
            direction: Inbound
      register: nsg
    - debug:
        var: nsg

And that’s it for this post! Thank you for reading!

Leave a Reply