Zim's Notes

Just work related notes.

Creating Azure Virtual Machines With Ansible and REST API

Just go to examples folder and run following playbook:

1
ansible-playbook compute_virtualmachines_put.yml

Please note that it will create all the necessary dependencies:

  • resource group
  • network interface
  • public IP address
  • virtual network with subnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
- import_playbook: network_networkinterfaces_put.yml
- hosts: localhost
  roles:
    - ../modules
  vars:
    subscription_id: ""
    resource_group: myResourceGroup
    virtual_machine_name: myVirtualMachine
    network_interface_name: myNetworkInterface
  tasks:
    - name: Create a vm with password authentication.
      azure_rm_resource:
        idempotency: yes
        api_version: '2018-10-01'
        polling_timeout: 600
        polling_interval: 30
        # url: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}
        resource_group: ''
        provider: Compute
        resource_type: virtualMachines
        resource_name: ""
        body:
          location: eastus
          properties:
            hardwareProfile:
              vmSize: Standard_D3_v2
            storageProfile:
              imageReference:
                sku: 2016-Datacenter
                publisher: MicrosoftWindowsServer
                version: latest
                offer: WindowsServer
              osDisk:
                caching: ReadWrite
                managedDisk:
                  storageAccountType: Standard_LRS
                name: myVMosdisk
                createOption: FromImage
            osProfile:
              adminUsername: adminxyz
              computerName: myVM
              adminPassword: MooMoo123!!!!
            networkProfile:
              networkInterfaces:
                - id: "/subscriptions//resourceGroups//providers/Microsoft.Network/networkInterfaces/"
                  properties:
                    primary: True