Description
Specify network_interfaces when an Azure VM should use a NIC you have reviewed. If you omit the NIC, Ansible can create one. Check which subnet and public IP the VM actually uses.
Potential impact
An automatically selected network or NSG can expose management ports more broadly than intended.
Remediation
Review the NIC and subnet NSGs, routes and any public IP association. Test access from the clients that need it. Using a prepared NIC lets you check these settings before creating the VM.
Examples
For the short module name, install azure.azcollection and include it in the play’s collections. In network_interfaces: testvm001, the value names an existing NIC. Both tasks use a custom image and a separately supplied vm_admin_password. no_log: true suppresses task output.
Before
- name: Create the VM
azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: adminUser
admin_password: "{{ vm_admin_password }}"
image: customimage001
no_log: true
After
- name: Create the VM
azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: adminUser
admin_password: "{{ vm_admin_password }}"
image: customimage001
network_interfaces: testvm001
no_log: true