From 0c88f199ec6f32b8b3c582564d1b62f332beff62 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 3 Apr 2018 06:32:01 +1000 Subject: [PATCH] azure_rm_networkinterface: backport no public IP fix (#37762) * azure_rm_networkinterface: fixed issue when public ip address should not be created (#36824) * fixed issue when public ip address should not be created * adding test for public ip address * fixed samples * another fix to sample formatting * fixed test * fix test * fixed test * another attempt to fix test * maybe it works now * still wrong * improved check per customer request * removed stupid semicolon * updated test to match main scenario * changed ip configurations to list * another attempt (cherry picked from commit 89401f13f761c94552fca8eafbaf5bcf54aff40c) * Added changelog fragment --- ...networkinterface-specify-no-public-ip.yaml | 2 + .../cloud/azure/azure_rm_networkinterface.py | 98 ++++++++++--------- .../azure_rm_networkinterface/tasks/main.yml | 16 +++ 3 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 changelogs/fragments/azure_rm_networkinterface-specify-no-public-ip.yaml diff --git a/changelogs/fragments/azure_rm_networkinterface-specify-no-public-ip.yaml b/changelogs/fragments/azure_rm_networkinterface-specify-no-public-ip.yaml new file mode 100644 index 00000000000..36654b77432 --- /dev/null +++ b/changelogs/fragments/azure_rm_networkinterface-specify-no-public-ip.yaml @@ -0,0 +1,2 @@ +bugfixes: +- azure_rm_networkinterface - fixed examples in module documentation and added fix to allow an IP configuration with no public IP (https://github.com/ansible/ansible/pull/36824) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py index 13ac61a3733..335526b947a 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py @@ -173,68 +173,68 @@ author: EXAMPLES = ''' - name: Create a network interface with minimal parameters azure_rm_networkinterface: - name: nic001 - resource_group: Testing - virtual_network_name: vnet001 - subnet_name: subnet001 - ip_configurations: - name: ipconfig1 - public_ip_address_name: publicip001 - primary: True + name: nic001 + resource_group: Testing + virtual_network_name: vnet001 + subnet_name: subnet001 + ip_configurations: + - name: ipconfig1 + public_ip_address_name: publicip001 + primary: True - name: Create a network interface with private IP address only (no Public IP) azure_rm_networkinterface: - name: nic001 - resource_group: Testing - virtual_network_name: vnet001 - subnet_name: subnet001 - ip_configurations: - name: ipconfig1 - primary: True + name: nic001 + resource_group: Testing + virtual_network_name: vnet001 + subnet_name: subnet001 + ip_configurations: + - name: ipconfig1 + primary: True - name: Create a network interface for use in a Windows host (opens RDP port) with custom RDP port azure_rm_networkinterface: - name: nic002 - resource_group: Testing - virtual_network_name: vnet001 - subnet_name: subnet001 - os_type: Windows - rdp_port: 3399 - ip_configurations: - name: ipconfig1 - public_ip_address_name: publicip001 - primary: True + name: nic002 + resource_group: Testing + virtual_network_name: vnet001 + subnet_name: subnet001 + os_type: Windows + rdp_port: 3399 + ip_configurations: + - name: ipconfig1 + public_ip_address_name: publicip001 + primary: True - name: Create a network interface using existing security group and public IP azure_rm_networkinterface: - name: nic003 - resource_group: Testing - virtual_network_name: vnet001 - subnet_name: subnet001 - security_group_name: secgroup001 - ip_configurations: - name: ipconfig1 - public_ip_address_name: publicip001 - primary: True + name: nic003 + resource_group: Testing + virtual_network_name: vnet001 + subnet_name: subnet001 + security_group_name: secgroup001 + ip_configurations: + - name: ipconfig1 + public_ip_address_name: publicip001 + primary: True - name: Create a network with mutilple ip configurations azure_rm_networkinterface: - name: nic004 - resource_group: Testing - subnet_name: subnet001 - virtual_network_name: vnet001 - security_group_name: secgroup001 - ip_configurations: - - name: ipconfig1 - public_ip_address_name: publicip001 - primary: True - - name: ipconfig2 + name: nic004 + resource_group: Testing + subnet_name: subnet001 + virtual_network_name: vnet001 + security_group_name: secgroup001 + ip_configurations: + - name: ipconfig1 + public_ip_address_name: publicip001 + primary: True + - name: ipconfig2 - name: Delete network interface azure_rm_networkinterface: - resource_group: Testing - name: nic003 - state: absent + resource_group: Testing + name: nic003 + state: absent ''' RETURN = ''' @@ -536,6 +536,10 @@ class AzureRMNetworkInterface(AzureRMModuleBase): def get_or_create_public_ip_address(self, ip_config): name = ip_config.get('public_ip_address_name') + + if not (self.public_ip and name): + return None + pip = self.get_public_ip_address(name) if not pip: params = self.network_models.PublicIPAddress( diff --git a/test/integration/targets/azure_rm_networkinterface/tasks/main.yml b/test/integration/targets/azure_rm_networkinterface/tasks/main.yml index 878ede79873..ec1bd1f613c 100644 --- a/test/integration/targets/azure_rm_networkinterface/tasks/main.yml +++ b/test/integration/targets/azure_rm_networkinterface/tasks/main.yml @@ -134,6 +134,22 @@ - not output.state.ip_configuration - output.state.ip_configurations | length == 2 +- name: IP configuration without public IP + azure_rm_networkinterface: + resource_group: "{{ resource_group }}" + name: testnic001noip + security_group: testnic001 + virtual_network: "{{ vn.state.id }}" + subnet: testnic001 + ip_configurations: + - name: ipconfig1 + primary: True + register: output + +- assert: + that: + - output.state.ip_configurations[0].public_ip_address == None + - name: Delete the NIC (check mode) azure_rm_networkinterface: resource_group: "{{ resource_group }}"