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.
- Create a resource group
- Create a virtual network
- Create a subnet within the virtual network
- Create a public IP address
- Create a network security group
- Create a virtual network interface card
- Create a storage account
- Create a virtual machine
- Interactively SSH into the virtual machine using Azure Cloud Shell
- Deallocate virtual machine
The following excerpts are shown below:
- The entire contents of the file that creates a network security group
- Interactive SSH session with the virtual machine
- 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!