I have created VM by using ansible but when the VM is created, the storage account is also created in Azure which I don't need. Is there anyone knows how can I create VM without have storage account.
Here is my ansible code
- name: Create windows vms
azure_rm_virtualmachine:
resource_group: "{{ RG_VMS }}"
name: "{{ item.key }}"
vm_size: Standard_B2ms
admin_username: user
admin_password: "{{ password }}"
network_interfaces: "{{ item.key }}-nic"
os_type: Windows
os_disk_name: disk{{ item.key }}
os_disk_size_gb: 127
os_disk_caching: ReadWrite
managed_disk_type: StandardSSD_LRS
image:
offer: WindowsServer
publisher: MicrosoftWindowsServer
sku: 2016-Datacenter
version: latest
tags:
otapenvironment: "{{ OTAPENVIRONMENT }}"
systemtype: "{{ item.value.systemtype }}"
loop: "{{ WINDOWS_VMS | dict2items }}"
I tried creating Azure VM with ansible by using the below script and it got created successfully like below:-
By default azurerm ansible provider requires storage account for storing VM's OS disk VHD configurations, If you do not want to create a Storage account, You need to create your VM with managed disk
Note:- storage_account_name Name of an existing storage account that supports creation of VHD blobs. If not specified for a new VM, a new storage account started with name will be created using storage type Standard_LRS. Only used when OS disk created with virtual hard disk (VHD). Used when managed_disk_type not defined.
Note Reference:- azure.azcollection.azure_rm_virtualmachine module – Manage Azure virtual machines — Ansible Documentation
With storage account for VHD:-
Code:-
#deployWindowsAzureVirtualMachine.yaml
---
- hosts: localhost
connection: local
vars_prompt:
- name: password
prompt: "Enter local administrator password"
tasks:
- name: Create resource group
azure_rm_resourcegroup:
name: rg-cs-ansible
location: eastus
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: rg-cs-ansible0987
name: vnet-cs-web
address_prefixes: "10.0.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: rg-cs-ansible0987
name: snet-cs-web
address_prefix: "10.0.1.0/24"
virtual_network: vnet-cs-web
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: rg-cs-ansible0987
allocation_method: Static
name: pip-cs-web
register: output_ip_address
- name: Output public IP
debug:
msg: "The public IP is {{ output_ip_address.state.ip_address }}"
- name: Create Network Security Group
azure_rm_securitygroup:
resource_group: rg-cs-ansible0987
name: nsg-cs-web
rules:
- name: 'allow_rdp'
protocol: Tcp
destination_port_range: 3389
access: Allow
priority: 1001
direction: Inbound
- name: 'allow_web_traffic'
protocol: Tcp
destination_port_range:
- 80
- 443
access: Allow
priority: 1002
direction: Inbound
- name: 'allow_powershell_remoting'
protocol: Tcp
destination_port_range:
- 5985
- 5986
access: Allow
priority: 1003
direction: Inbound
- name: Create a network interface
azure_rm_networkinterface:
name: nic-cs-web
resource_group: rg-cs-ansible0987
virtual_network: vnet-cs-web
subnet_name: snet-cs-web
security_group: nsg-cs-web
ip_configurations:
- name: default
public_ip_address_name: pip-cs-web
primary: True
- name: Create VM
azure_rm_virtualmachine:
resource_group: rg-cs-ansible0987
name: vm-cs-web01
vm_size: Standard_DS1_v2
admin_username: azureuser
admin_password: "{{ password }}"
network_interfaces: nic-cs-web
os_type: Windows
image:
offer: WindowsServer
publisher: MicrosoftWindowsServer
sku: 2019-Datacenter
version: latest
Output:-
Storage account created for VHD :-
Without Storage account with managed disk:-
Code:-
- hosts: localhost
connection: local
vars_prompt:
- name: password
prompt: "Enter local administrator password"
tasks:
- name: Create resource group
azure_rm_resourcegroup:
name: rg-cs-ansible0987
location: eastus
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: rg-cs-ansible0987
name: vnet-cs-web3
address_prefixes: "10.0.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: rg-cs-ansible0987
name: snet-cs-web3
address_prefix: "10.0.1.0/24"
virtual_network: vnet-cs-web3
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: rg-cs-ansible0987
allocation_method: Static
name: pip-cs-web3
register: output_ip_address
- name: Output public IP
debug:
msg: "The public IP is {{ output_ip_address.state.ip_address }}"
- name: Create Network Security Group
azure_rm_securitygroup:
resource_group: rg-cs-ansible0987
name: nsg-cs-web3
rules:
- name: 'allow_rdp'
protocol: Tcp
destination_port_range: 3389
access: Allow
priority: 1001
direction: Inbound
- name: 'allow_web_traffic'
protocol: Tcp
destination_port_range:
- 80
- 443
access: Allow
priority: 1002
direction: Inbound
- name: 'allow_powershell_remoting'
protocol: Tcp
destination_port_range:
- 5985
- 5986
access: Allow
priority: 1003
direction: Inbound
- name: Create a network interface
azure_rm_networkinterface:
name: nic-cs-web3
resource_group: rg-cs-ansible0987
virtual_network: vnet-cs-web3
subnet_name: snet-cs-web3
security_group: nsg-cs-web3
ip_configurations:
- name: default
public_ip_address_name: pip-cs-web3
primary: True
- name: Create VM
azure_rm_virtualmachine:
resource_group: rg-cs-ansible0987
name: vm-cs-web01234
vm_size: Standard_DS1_v2
managed_disk_type: Premium_LRS
admin_username: azureuser
admin_password: "{{ password }}"
network_interfaces: nic-cs-web3
os_type: Windows
image:
offer: WindowsServer
publisher: MicrosoftWindowsServer
sku: 2019-Datacenter
version: latest
Output:-
VM managed disk is created like below without a need for storage account:-
Reference :-