azure_rm_common: only remove tags from new_tags if append_tags is not… (#24040)

This commit is contained in:
Bjorn Hansen 2018-08-15 20:35:39 -07:00 committed by Yunge Zhu
parent babfe45852
commit ff6d4e6bf4
5 changed files with 20 additions and 14 deletions

View file

@ -464,17 +464,20 @@ class AzureRMModuleBase(object):
:return: bool, dict :return: bool, dict
''' '''
new_tags = copy.copy(tags) if isinstance(tags, dict) else 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 changed = False
if isinstance(self.module.params.get('tags'), dict): # check add or update
for key, value in self.module.params['tags'].items(): for key, value in param_tags.items():
if not new_tags.get(key) or new_tags[key] != value: 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 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 return changed, new_tags
def has_tags(self, obj_tags, tag_list): def has_tags(self, obj_tags, tag_list):

View file

@ -33,9 +33,6 @@
name: "pip{{ rpfx }}" name: "pip{{ rpfx }}"
allocation_method: Static allocation_method: Static
domain_name: "{{ domain_name }}" domain_name: "{{ domain_name }}"
tags:
testing: testing
delete: on-exit
register: output register: output
- assert: - assert:
@ -45,8 +42,8 @@
azure_rm_publicipaddress: azure_rm_publicipaddress:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
name: "pip{{ rpfx }}" name: "pip{{ rpfx }}"
append_tags: yes
tags: tags:
testing: testing
delete: never delete: never
foo: bar foo: bar
register: output register: output
@ -70,7 +67,7 @@
azure_rm_publicipaddress: azure_rm_publicipaddress:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
name: "pip{{ rpfx }}" name: "pip{{ rpfx }}"
tags: {} append_tags: no
register: output register: output
- assert: - assert:

View file

@ -94,6 +94,7 @@
testing: testing testing: testing
delete: never delete: never
baz: bar baz: bar
append_tags: false
register: output register: output
- assert: - assert:
@ -105,6 +106,7 @@
azure_rm_securitygroup: azure_rm_securitygroup:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
name: "{{ secgroupname }}" name: "{{ secgroupname }}"
append_tags: false
tags: tags:
testing: testing testing: testing
delete: on-exit delete: on-exit

View file

@ -24,6 +24,7 @@
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
name: "{{ storage_account }}" name: "{{ storage_account }}"
account_type: Standard_LRS account_type: Standard_LRS
append_tags: no
tags: tags:
test: test test: test
galaxy: galaxy galaxy: galaxy
@ -72,6 +73,7 @@
azure_rm_storageaccount: azure_rm_storageaccount:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
name: "{{ storage_account }}" name: "{{ storage_account }}"
append_tags: no
tags: tags:
testing: testing testing: testing
delete: never delete: never
@ -87,6 +89,7 @@
azure_rm_storageaccount: azure_rm_storageaccount:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
name: "{{ storage_account }}" name: "{{ storage_account }}"
append_tags: no
tags: tags:
testing: testing testing: testing
delete: never delete: never

View file

@ -102,6 +102,7 @@
- name: Purge tags - name: Purge tags
azure_rm_virtualnetwork: azure_rm_virtualnetwork:
name: "{{ vnetname }}" name: "{{ vnetname }}"
append_tags: no
tags: tags:
testing: 'always' testing: 'always'
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"