adambrassard.azure_virtualmachine

Create/Update VM in Azure

This role helps to create or update virtual machines (VMs) in Azure.

For more details, check the Azure RM Virtual Machine Module.

Requirements

  • You need the Azure_rm Module.
  • Ansible version must be 2.8 or higher.
  • This has been tested with Ansible version 2.13.1.

To install the Azure Collection from Galaxy:

ansible-galaxy collection install azure.azcollection

To install the required Python packages from the collection:

sudo pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt

User Defined Role Variables

# Default required variables:
resource_group: 
location: 

# VM information
vm:
  - name: # unique name for the VM
    size: # Example: "Standard_D4s_v3" (size of the VM)
    offer: # Example: "RHEL" (OS flavor)
    publisher: # Example: "RedHat" (company name publishing the image)
    sku_name: # Example: "7-RAW" (main OS version)
    sku_version: # Example: "latest" (specific OS version)
    os_type: # Example: Windows, Linux
    managed_disk_type: # Storage type: Standard_LRS or Premium_LRS. Defaults to Standard_LRS if not specified.
    os_disk_caching: # Default is 'ReadOnly', can also be "ReadWrite".
    os_disk_size_gb: # Minimum for Windows 2012 is 127 GB; specify size if not using default.
    vm_username: # Example: "azureadmin"
    vm_password:  # Set a password
    avset_name: # Optional availability set name
    nic_name: # Name of an existing Network Interface Card (NIC)
    pubip: # Set public IP as 'static' or 'dynamic'; defaults to disabled.
    subnet_name: # Name of the subnet for the VM; multiple subnets can be used.

Dependencies

If you don't specify the NIC name, a new one will be created if a network exists in the resource group. You can set the NIC name if it already exists.

Example Playbook

Creating Multiple VMs in One Playbook

---
- name: Azure Playbook to create multiple VMs
  hosts: localhost

  pre_tasks:
    - name: Creating multiple VMs in one resource group
      set_fact:
        # Default required vars
        resource_group: "MyRG"
        location: "canadacentral"

        # VM structure for multiple VM input
        vm:
          - name: NewVM
            size: "Standard_D4s_v3"
            offer: "RHEL"
            publisher: "RedHat"
            sku_name: "7-RAW"
            sku_version: "latest"
            os_type: Linux
            managed_disk_type: Standard_LRS
            os_disk_size_gb: 150
            vm_username: "TempAdmin"
            vm_password: "YouShouldntUseClearTextPasswords@!"
            avset_name: "myavset4"
            pubip: "static"

          - name: SecondGreatVm
            size: "Standard_D4s_v3"
            offer: "RHEL"
            publisher: "RedHat"
            sku_name: "7-RAW"
            sku_version: "latest"
            os_type: Linux
            managed_disk_type: Premium_LRS
            os_disk_size_gb: 200
            vm_username: "TempAdmin"
            vm_password: "YouShouldntUseClearTextPasswords@!"
            avset_name: "myavset4"

          - name: MyThirdVM
            size: "Standard_DS2_v2"
            offer: "WindowsServer"
            publisher: "MicrosoftWindowsServer"
            sku_name: "2019-Datacenter"
            sku_version: "latest"
            os_type: "Windows"
            managed_disk_type: StandardSSD_LRS
            os_disk_size_gb: 200
            vm_username: "TempAdmin"
            vm_password: "YouShouldntUseClearTextPasswords@!"
            avset_name: "windowsAVset"

  connection: local
  roles:
    - azure-virtualmachine

Creating a VM Using a Preexisting NIC

---
- name: Azure Playbook to create a VM with an existing NIC
  hosts: localhost

  pre_tasks:
    - name: Creating a VM with an existing NIC and specifying OS disk caching type
      set_fact:
        # Default required vars
        resource_group: "MyRG"
        location: "canadacentral"

        # VM structure for input
        vm:
          - name: NewVM
            size: "Standard_D4s_v3"
            offer: "RHEL"
            publisher: "RedHat"
            sku_name: "7-RAW"
            sku_version: "latest"
            os_type: Linux
            os_disk_caching: "ReadOnly"
            managed_disk_type: Standard_LRS
            os_disk_size_gb: 150
            vm_username: "TempAdmin"
            vm_password: "YouShouldntUseClearTextPasswords@!"
            avset_name: "myavset4"
            nic_name: "oldnic2019"

  connection: local
  roles:
    - azure-virtualmachine

License

MIT

Author Information

Adam Brassard: Abrass on IRC

Informazioni sul progetto

A role to create multiple VMs in Azure

Installa
ansible-galaxy install adambrassard.azure_virtualmachine
Licenza
mit
Download
88
Proprietario