From 7c201fc9bc1ff868bea511211583febb0ac25543 Mon Sep 17 00:00:00 2001 From: Yuwei Zhou Date: Thu, 25 Jan 2018 08:59:14 +0800 Subject: [PATCH] delete subnet should be idempotent (#35037) --- lib/ansible/modules/cloud/azure/azure_rm_subnet.py | 2 +- .../targets/azure_rm_subnet/tasks/main.yml | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py index 6b8a407923..d7e375b609 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py @@ -254,7 +254,7 @@ class AzureRMSubnet(AzureRMModuleBase): resource_guid=nsg.resource_guid) self.results['state'] = self.create_or_update_subnet(subnet) - elif self.state == 'absent': + elif self.state == 'absent' and changed: # delete subnet self.delete_subnet() # the delete does not actually return anything. if no exception, then we'll assume diff --git a/test/integration/targets/azure_rm_subnet/tasks/main.yml b/test/integration/targets/azure_rm_subnet/tasks/main.yml index 9a32ee3766..a29df1fdd8 100644 --- a/test/integration/targets/azure_rm_subnet/tasks/main.yml +++ b/test/integration/targets/azure_rm_subnet/tasks/main.yml @@ -82,6 +82,17 @@ virtual_network_name: My_Virtual_Network resource_group: "{{ resource_group }}" +- name: Remove subnet (idempotent) + azure_rm_subnet: + state: absent + name: foobar + virtual_network_name: My_Virtual_Network + resource_group: "{{ resource_group }}" + register: output + +- assert: + that: not output.changed + - name: Remove security group azure_rm_securitygroup: resource_group: "{{ resource_group }}"