Azure fix _info/_facts return values for some modules (#61584)

* Azure fix _info/_facts return values for some modules

* Further test fixes

* securitygroup fixes after the move to _info module

(cherry picked from commit 951dac7691)
This commit is contained in:
Jordan Borean 2019-08-30 16:00:47 +10:00 committed by Toshio Kuratomi
parent 391a67401d
commit a271cb6136
6 changed files with 35 additions and 24 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- azure_rm_securitygroup_info - Fix up instances when ``ansible_facts`` is returned for the older ``_facts`` alias.
- azure_rm_networkinterface_info - Fix up instances when ``ansible_facts`` is returned for the older ``_facts`` alias.

View file

@ -273,7 +273,6 @@ class AzureRMNetworkInterfaceInfo(AzureRMModuleBase):
self.results = dict(
changed=False,
ansible_info=dict(azure_networkinterfaces=[])
)
self.name = None
@ -307,7 +306,10 @@ class AzureRMNetworkInterfaceInfo(AzureRMModuleBase):
else:
results = self.list_all()
self.results['ansible_info']['azure_networkinterfaces'] = self.serialize_nics(results)
if is_old_facts:
self.results['ansible_facts'] = {
'azure_networkinterfaces': self.serialize_nics(results)
}
self.results['networkinterfaces'] = self.to_dict_list(results)
return self.results

View file

@ -207,7 +207,6 @@ class AzureRMPublicIPInfo(AzureRMModuleBase):
self.results = dict(
changed=False,
ansible_facts=dict(azure_publicipaddresses=[])
)
self.name = None
@ -240,7 +239,9 @@ class AzureRMPublicIPInfo(AzureRMModuleBase):
raw = self.filter(result)
if is_old_facts:
self.results['ansible_facts']['azure_publicipaddresses'] = self.serialize(raw)
self.results['ansible_facts'] = {
'azure_publicipaddresses': self.serialize(raw),
}
self.results['publicipaddresses'] = self.format(raw)
return self.results

View file

@ -59,7 +59,7 @@ EXAMPLES = '''
'''
RETURN = '''
azure_securitygroups:
securitygroups:
description:
- List containing security group dicts.
returned: always
@ -247,7 +247,6 @@ class AzureRMSecurityGroupInfo(AzureRMModuleBase):
self.results = dict(
changed=False,
ansible_info=dict(azure_securitygroups=[])
)
self.name = None
@ -268,9 +267,15 @@ class AzureRMSecurityGroupInfo(AzureRMModuleBase):
setattr(self, key, kwargs[key])
if self.name is not None:
self.results['ansible_info']['azure_securitygroups'] = self.get_item()
info = self.get_item()
else:
self.results['ansible_info']['azure_securitygroups'] = self.list_items()
info = self.list_items()
if is_old_facts:
self.results['ansible_facts'] = {
'azure_securitygroups': info
}
self.results['securitygroups'] = info
return self.results

View file

@ -35,7 +35,7 @@
- assert: { that: "{{ output.state.rules | length }} == 2" }
- name: Gather facts by tags
azure_rm_securitygroup_facts:
azure_rm_securitygroup_info:
resource_group: "{{ resource_group }}"
tags:
- testing
@ -43,7 +43,7 @@
register: output
- assert:
that: azure_securitygroups | length == 1
that: output.securitygroups | length == 1
- name: Add/Update rules on existing security group
azure_rm_securitygroup:
@ -121,23 +121,23 @@
- output.state.tags.delete == 'on-exit'
- name: Gather facts for one accounts
azure_rm_securitygroup_facts:
azure_rm_securitygroup_info:
resource_group: "{{ resource_group }}"
name: "{{ secgroupname }}"
register: output
- assert:
that:
- azure_securitygroups | length == 1
- output.securitygroups | length == 1
- name: Gather facts for all accounts
azure_rm_securitygroup_facts:
azure_rm_securitygroup_info:
resource_group: "{{ resource_group }}"
register: output
register: output_groups
- assert:
that:
- azure_securitygroups | length > 0
- output_groups.securitygroups | length > 0
- name: Create security group with source_address_prefixes
azure_rm_securitygroup:
@ -290,13 +290,13 @@
resource_group: "{{ resource_group }}"
name: "{{ item.name }}"
state: absent
with_items: "{{ azure_securitygroups }}"
with_items: "{{ output_groups.securitygroups }}"
- name: Should have no security groups remaining
azure_rm_securitygroup_facts:
azure_rm_securitygroup_info:
resource_group: "{{ resource_group }}"
register: output
- assert:
that:
- azure_securitygroups | length == 0
- output.securitygroups | length == 0

View file

@ -66,19 +66,19 @@
state: absent
- name: Query auto created NIC
azure_rm_networkinterface_facts:
azure_rm_networkinterface_info:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}01"
register: nic_result
- name: Query auto created security group
azure_rm_securitygroup_facts:
azure_rm_securitygroup_info:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}01"
register: nsg_result
- name: Query auto created public IP
azure_rm_publicipaddress_facts:
azure_rm_publicipaddress_info:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}01"
register: pip_result
@ -87,9 +87,9 @@
assert:
that:
# what about the default storage group?
- nic_result.ansible_facts.azure_networkinterfaces | length == 0
- nsg_result.ansible_facts.azure_securitygroups | length == 0
- pip_result.ansible_facts.azure_publicipaddresses | length == 0
- nic_result.networkinterfaces | length == 0
- nsg_result.securitygroups | length == 0
- pip_result.publicipaddresses | length == 0
- name: Destroy subnet
azure_rm_subnet: