From ff6d4e6bf4a34dce58ce4396430d22dfa74b9121 Mon Sep 17 00:00:00 2001 From: Bjorn Hansen Date: Wed, 15 Aug 2018 20:35:39 -0700 Subject: [PATCH] =?UTF-8?q?azure=5Frm=5Fcommon:=20only=20remove=20tags=20f?= =?UTF-8?q?rom=20new=5Ftags=20if=20append=5Ftags=20is=20not=E2=80=A6=20(#2?= =?UTF-8?q?4040)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ansible/module_utils/azure_rm_common.py | 21 +++++++++++-------- .../azure_rm_publicipaddress/tasks/main.yml | 7 ++----- .../azure_rm_securitygroup/tasks/main.yml | 2 ++ .../azure_rm_storageaccount/tasks/main.yml | 3 +++ .../azure_rm_virtualnetwork/tasks/main.yml | 1 + 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index 896e5e93c7..61c27988b9 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -464,17 +464,20 @@ class AzureRMModuleBase(object): :return: bool, dict ''' new_tags = copy.copy(tags) if isinstance(tags, dict) else dict() + param_tags = self.module.params.get('tags') if isinstance(self.module.params.get('tags'), dict) else dict() + append_tags = self.module.params.get('append_tags') if self.module.params.get('append_tags') is not None else True changed = False - if isinstance(self.module.params.get('tags'), dict): - for key, value in self.module.params['tags'].items(): - if not new_tags.get(key) or new_tags[key] != value: + # check add or update + for key, value in param_tags.items(): + if not new_tags.get(key) or new_tags[key] != value: + changed = True + new_tags[key] = value + # check remove + if not append_tags: + for key, value in tags.items(): + if not param_tags.get(key): + new_tags.pop(key) changed = True - new_tags[key] = value - if isinstance(tags, dict): - for key, value in tags.items(): - if not self.module.params['tags'].get(key): - new_tags.pop(key) - changed = True return changed, new_tags def has_tags(self, obj_tags, tag_list): diff --git a/test/integration/targets/azure_rm_publicipaddress/tasks/main.yml b/test/integration/targets/azure_rm_publicipaddress/tasks/main.yml index 16b22a1e8a..91f67750b1 100644 --- a/test/integration/targets/azure_rm_publicipaddress/tasks/main.yml +++ b/test/integration/targets/azure_rm_publicipaddress/tasks/main.yml @@ -33,9 +33,6 @@ name: "pip{{ rpfx }}" allocation_method: Static domain_name: "{{ domain_name }}" - tags: - testing: testing - delete: on-exit register: output - assert: @@ -45,8 +42,8 @@ azure_rm_publicipaddress: resource_group: "{{ resource_group }}" name: "pip{{ rpfx }}" + append_tags: yes tags: - testing: testing delete: never foo: bar register: output @@ -70,7 +67,7 @@ azure_rm_publicipaddress: resource_group: "{{ resource_group }}" name: "pip{{ rpfx }}" - tags: {} + append_tags: no register: output - assert: diff --git a/test/integration/targets/azure_rm_securitygroup/tasks/main.yml b/test/integration/targets/azure_rm_securitygroup/tasks/main.yml index 74968fdfdb..073c10bffa 100644 --- a/test/integration/targets/azure_rm_securitygroup/tasks/main.yml +++ b/test/integration/targets/azure_rm_securitygroup/tasks/main.yml @@ -94,6 +94,7 @@ testing: testing delete: never baz: bar + append_tags: false register: output - assert: @@ -105,6 +106,7 @@ azure_rm_securitygroup: resource_group: "{{ resource_group }}" name: "{{ secgroupname }}" + append_tags: false tags: testing: testing delete: on-exit diff --git a/test/integration/targets/azure_rm_storageaccount/tasks/main.yml b/test/integration/targets/azure_rm_storageaccount/tasks/main.yml index ec1dc70c4d..a315be4a02 100644 --- a/test/integration/targets/azure_rm_storageaccount/tasks/main.yml +++ b/test/integration/targets/azure_rm_storageaccount/tasks/main.yml @@ -24,6 +24,7 @@ resource_group: "{{ resource_group }}" name: "{{ storage_account }}" account_type: Standard_LRS + append_tags: no tags: test: test galaxy: galaxy @@ -72,6 +73,7 @@ azure_rm_storageaccount: resource_group: "{{ resource_group }}" name: "{{ storage_account }}" + append_tags: no tags: testing: testing delete: never @@ -87,6 +89,7 @@ azure_rm_storageaccount: resource_group: "{{ resource_group }}" name: "{{ storage_account }}" + append_tags: no tags: testing: testing delete: never diff --git a/test/integration/targets/azure_rm_virtualnetwork/tasks/main.yml b/test/integration/targets/azure_rm_virtualnetwork/tasks/main.yml index b42378e897..0c1dc76cb9 100644 --- a/test/integration/targets/azure_rm_virtualnetwork/tasks/main.yml +++ b/test/integration/targets/azure_rm_virtualnetwork/tasks/main.yml @@ -102,6 +102,7 @@ - name: Purge tags azure_rm_virtualnetwork: name: "{{ vnetname }}" + append_tags: no tags: testing: 'always' resource_group: "{{ resource_group }}"