Closed venkateshm2012 closed 2 months ago
@venkateshm2012 Thanks for your questions! To use a module from Azure collection, you should reference the full namespace or collection name, you can try like the follow. Another, Can you provide your full use case and use the azure-collecitons version? Will help solve the current problem, thank you!
First way(use namespace):
---
- name: Using Azure collection
hosts: localhost
collections:
- azure.azcollection
tasks:
- name: For network interface test
azure_rm_networkinterface:
....................................
Second way( use collections name):
---
- name: Using Azure collection
hosts: localhost
tasks:
- name: For network interface test
azure.azcollection.azure_rm_networkinterface:
....................................
Same issue for me. I don't want to delete or change the existing primary or secondary interfaces. I just want to add an additional secondary Name with a dynamic IP. However it seems like it wants to update the primary? So not sure what I am missing, or is it the case that you have to respecify all ip_configurations for all interfaces.
error message reported. "Deletion and renaming of primary IP Configuration is not supported"
ansible play
- name: Create IP for Network Interfaces
azure.azcollection.azure_rm_networkinterface:
resource_group: "{{ ResGroup }}"
virtual_network: "{{ VNet }}"
subnet_name: "{{ SubnetName }}"
name: "{{ item.name }}"
ip_configurations:
- name: "{{ item.ip_config_name }}"
primary: false
state: present
profile: e3
loop:
- { name: "{{ NetworkInterfaceName1 }}", ip_config_name: "{{ IpConfigName1 }}" }
register: nic_result
error message during run of task.
failed: [localhost] (item={'name': 'obfuscated', 'ip_config_name': 'obfuscated'}) => {"ansible_loop_var": "item", "changed": false, "item": {"ip_config_name": "obfuscated", "name": "obfuscated"}, "msg": "Error creating or updating network interface obfuscated - (IpConfigDeleteNotSupported) IP Configuration obfuscated cannot be deleted. Deletion and renaming of primary IP Configuration is not supported\nCode: IpConfigDeleteNotSupported\nMessage: IP Configuration obfuscated cannot be deleted. Deletion and renaming of primary IP Configuration is not supported"}
ansible collection. azure.azcollection 1.18.1
So, after some exploration, I've discovered an important caveat: the approach of directly adding IP configurations using a loop can lead to unintended behavior. It seems that this method overwrites existing configurations rather than adding new ones.
In my scenario, I needed to set up multiple secondary IP addresses on a network interface, but this method condensed them into a single entry, which was definitely not the desired outcome.
To illustrate a more effective strategy, consider the following setup using a predefined ipConfig variable:
- set_fact:
ipConfig:
- name: "ip-ext0-TestAnsible"
primary: true
private_ip_allocation_method: "Dynamic"
- name: "ip-ext0-TestAnsible1"
primary: false
private_ip_allocation_method: "Dynamic"
- name: "ip-ext0-TestAnsible2"
primary: false
private_ip_allocation_method: "Dynamic"
Once ipConfig is established, you can proceed to assign the IP addresses as demonstrated below:
- name: Create IP for Network Interfaces
azure.azcollection.azure_rm_networkinterface:
resource_group: "{{ ResGroup }}"
virtual_network: "{{ VNet }}"
subnet_name: "{{ SubnetName }}"
name: "{{ NetworkInterfaceName1 }}"
ip_configurations: "{{ ipConfig }}"
state: present
Avoid the temptation to employ a loop in the manner shown below, as it will lead to unintended overwriting of entries:
- name: Create IP for Network Interfaces
azure.azcollection.azure_rm_networkinterface:
resource_group: "{{ ResGroup }}"
virtual_network: "{{ VNet }}"
subnet_name: "{{ SubnetName }}"
name: "{{ item.name }}"
ip_configurations:
- name: "{{ item.ip_config_name }}"
primary: "{{ item.Primary_Flag }}"
state: present
profile: e3f5drtest
loop:
- { name: "{{ NetworkInterfaceName1 }}", ip_config_name: "{{ IpConfigName1 }}", Primary_Flag: true }
- { name: "{{ NetworkInterfaceName1 }}", ip_config_name: "{{ IpConfigName2 }}", Primary_Flag: false }
- { name: "{{ NetworkInterfaceName1 }}", ip_config_name: "{{ IpConfigName3 }}", Primary_Flag: false }
This method feels quite cumbersome, especially compared to other options like PowerShell, where a single call can effortlessly add an IP address. I'm left wondering if I've overlooked a more efficient approach here. I'm curious if this behavior is intentional and if there's a rationale behind it. If anyone has insights or suggestions, I'd be eager to hear them.
@morley461 I see! I will recheck it! Thank you very much!
@venkateshm2012 Added in #1488
@venkateshm2012 @morley461 Sorry, we can't do the same as #1488 for the time being. Currently, the SDK of the network adapter does not support updating the ip_configuration information of the network adapter, and only supports re-creation. Therefore, if you want to configure multiple ip_configuration information for the NIC, perform the following operations. Thank you!
- name: Create IP for Network Interfaces
azure.azcollection.azure_rm_networkinterface:
resource_group: "{{ ResGroup }}"
virtual_network: "{{ VNet }}"
subnet_name: "{{ SubnetName }}"
name: "{{ item.name }}"
ip_configurations:
- name: "name1"
primary: "value1"
- name: "name2"
primary: "value2"
......
state: present
profile: e3f5drtest
@venkateshm2012 @morley461 If the SDK supports updates, we will import them as soon as possible. Thank you!
SUMMARY
unable to create secondary ip for a NIC
ISSUE TYPE
COMPONENT NAME
azure_rm_networkinterface module
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
I want to attach a new IPconfiguration on the NIC(MY_NIC) , in other words i need to attach secondary IP for the NIC.
ACTUAL RESULTS