Skip to content

Instantly share code, notes, and snippets.

@nidr0x
Created March 14, 2018 11:37
Show Gist options
  • Save nidr0x/affd021992b78fab4238186f16492a45 to your computer and use it in GitHub Desktop.
Save nidr0x/affd021992b78fab4238186f16492a45 to your computer and use it in GitHub Desktop.
Creating Azure VM in Ansible
- name: Create Azure VM
hosts: localhost
connection: local
tasks:
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: myResourceGroup
name: myVnet
address_prefixes: "10.0.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: myResourceGroup
name: mySubnet
address_prefix: "10.0.1.0/24"
virtual_network: myVnet
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: myResourceGroup
allocation_method: Static
name: myPublicIP
- name: Create Network Security Group that allows SSH
azure_rm_securitygroup:
resource_group: myResourceGroup
name: myNetworkSecurityGroup
rules:
- name: SSH
protocol: Tcp
destination_port_range: 22
access: Allow
priority: 1001
direction: Inbound
- name: Create virtual network inteface card
azure_rm_networkinterface:
resource_group: myResourceGroup
name: myNIC
virtual_network: myVnet
subnet: mySubnet
public_ip_name: myPublicIP
security_group: myNetworkSecurityGroup
- name: Create VM
azure_rm_virtualmachine:
resource_group: myResourceGroup
name: myVM
vm_size: Standard_DS1_v2
admin_username: azureuser
ssh_password_enabled: false
ssh_public_keys:
- path: /home/azureuser/.ssh/authorized_keys
key_data: "ssh-rsa AAAAB3Nz{snip}hwhqT9h"
network_interfaces: myNIC
image:
offer: CentOS
publisher: OpenLogic
sku: '7.3'
version: latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment