Skip to content

Instantly share code, notes, and snippets.

@AlexMikhalev
Created May 5, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMikhalev/ebf3c65817774830821bb396a6708efe to your computer and use it in GitHub Desktop.
Save AlexMikhalev/ebf3c65817774830821bb396a6708efe to your computer and use it in GitHub Desktop.
Ansible playbook to create Azure VM
- name: Create Azure VM
hosts: localhost
connection: local
tasks:
- name: Create resource group
azure_rm_resourcegroup:
name: cord19demo
location: westeurope
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: cord19demo
name: myVnet
address_prefixes: "10.0.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: cord19demo
name: mySubnet
address_prefix: "10.0.1.0/24"
virtual_network: myVnet
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: cord19demo
allocation_method: Static
name: myPublicIP
register: output_ip_address
- name: Dump public IP for VM which will be created
debug:
msg: "The public IP is {{ output_ip_address.state.ip_address }}."
- name: Create Network Security Group that allows SSH
azure_rm_securitygroup:
resource_group: cord19demo
name: myNetworkSecurityGroup
rules:
- name: SSH
protocol: Tcp
destination_port_range: 22
access: Allow
priority: 1001
direction: Inbound
- name: Create virtual network interface card
azure_rm_networkinterface:
resource_group: cord19demo
name: myNIC
virtual_network: myVnet
subnet: mySubnet
public_ip_name: myPublicIP
security_group: myNetworkSecurityGroup
- name: Create VM
azure_rm_virtualmachine:
resource_group: cord19demo
name: instance1
vm_size: Standard_E2s_v3
admin_username: alex
ssh_password_enabled: false
ssh_public_keys:
- path: /home/alex/.ssh/authorized_keys
key_data: *
network_interfaces: myNIC
image:
offer: UbuntuServer
publisher: Canonical
sku: '18.04-LTS'
version: latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment