Azure _info modules: fix returned ansible_facts when called as _info (#61805)

* Fix Azure _info modules which still returned ansible_facts.

* Adjust PR #.

* Fix wrong assignment.

* Reorganize code for clarity.
pull/61838/head
Felix Fontein 5 years ago committed by GitHub
parent 2a932ad7cf
commit e06dbe6e4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,7 @@
bugfixes:
- "azure_rm_dnsrecordset_info - no longer returns empty ``azure_dnsrecordset`` facts when called as ``_info`` module."
- "azure_rm_resourcegroup_info - no longer returns ``azure_resourcegroups`` facts when called as ``_info`` module."
- "azure_rm_storageaccount_info - no longer returns empty ``azure_storageaccounts`` facts when called as ``_info`` module."
- "azure_rm_virtualmachineimage_info - no longer returns empty ``azure_vmimages`` facts when called as ``_info`` module."
- "azure_rm_virtualmachinescaleset_info - fix wrongly empty result, or ``ansible_facts`` result, when called as ``_info`` module."
- "azure_rm_virtualnetwork_info - no longer returns empty ``azure_virtualnetworks`` facts when called as ``_info`` module."

@ -202,7 +202,6 @@ class AzureRMContainerInstanceInfo(AzureRMModuleBase):
# store the results of the module operation # store the results of the module operation
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict()
) )
self.resource_group = None self.resource_group = None
self.name = None self.name = None

@ -179,7 +179,6 @@ class AzureRMRecordSetInfo(AzureRMModuleBase):
# store the results of the module operation # store the results of the module operation
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_info=dict(azure_dnsrecordset=[])
) )
self.relative_name = None self.relative_name = None
@ -221,7 +220,9 @@ class AzureRMRecordSetInfo(AzureRMModuleBase):
results = self.list_zone() results = self.list_zone()
if is_old_facts: if is_old_facts:
self.results['ansible_facts']['azure_dnsrecordset'] = self.serialize_list(results) self.results['ansible_facts'] = {
'azure_dnsrecordset': self.serialize_list(results)
}
self.results['dnsrecordsets'] = self.curated_list(results) self.results['dnsrecordsets'] = self.curated_list(results)
return self.results return self.results

@ -154,7 +154,6 @@ class AzureRMResourceGroupInfo(AzureRMModuleBase):
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict(azure_resourcegroups=[]),
resourcegroups=[] resourcegroups=[]
) )
@ -167,20 +166,25 @@ class AzureRMResourceGroupInfo(AzureRMModuleBase):
facts_module=True) facts_module=True)
def exec_module(self, **kwargs): def exec_module(self, **kwargs):
is_old_facts = self.module._name == 'azure_rm_resourcegroup_facts'
if is_old_facts:
self.module.deprecate("The 'azure_rm_resourcegroup_facts' module has been renamed to 'azure_rm_resourcegroup_info'", version='2.13')
for key in self.module_arg_spec: for key in self.module_arg_spec:
setattr(self, key, kwargs[key]) setattr(self, key, kwargs[key])
if self.name: if self.name:
self.results['ansible_facts']['azure_resourcegroups'] = self.get_item() result = self.get_item()
else: else:
self.results['ansible_facts']['azure_resourcegroups'] = self.list_items() result = self.list_items()
if self.list_resources: if self.list_resources:
for item in self.results['ansible_facts']['azure_resourcegroups']: for item in result:
item['resources'] = self.list_by_rg(item['name']) item['resources'] = self.list_by_rg(item['name'])
self.results['resourcegroups'] = self.results['ansible_facts']['azure_resourcegroups'] if is_old_facts:
self.results['ansible_facts']['azure_resourcegroups'] = result
self.results['resourcegroups'] = result
return self.results return self.results

@ -138,7 +138,6 @@ class AzureRMSqlServerInfo(AzureRMModuleBase):
# store the results of the module operation # store the results of the module operation
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict()
) )
self.resource_group = None self.resource_group = None
self.server_name = None self.server_name = None

@ -371,7 +371,6 @@ class AzureRMStorageAccountInfo(AzureRMModuleBase):
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict(azure_storageaccounts=[]),
storageaccounts=[] storageaccounts=[]
) )
@ -407,8 +406,10 @@ class AzureRMStorageAccountInfo(AzureRMModuleBase):
filtered = self.filter_tag(results) filtered = self.filter_tag(results)
if is_old_facts: if is_old_facts:
self.results['ansible_facts']['azure_storageaccounts'] = self.serialize(filtered) self.results['ansible_facts'] = {
self.results['ansible_facts']['storageaccounts'] = self.format_to_dict(filtered) 'azure_storageaccounts': self.serialize(filtered),
'storageaccounts': self.format_to_dict(filtered),
}
self.results['storageaccounts'] = self.format_to_dict(filtered) self.results['storageaccounts'] = self.format_to_dict(filtered)
return self.results return self.results

@ -139,7 +139,6 @@ class AzureRMVirtualMachineImageInfo(AzureRMModuleBase):
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict(azure_vmimages=[])
) )
self.location = None self.location = None
@ -159,6 +158,7 @@ class AzureRMVirtualMachineImageInfo(AzureRMModuleBase):
setattr(self, key, kwargs[key]) setattr(self, key, kwargs[key])
if is_old_facts: if is_old_facts:
self.results['ansible_facts'] = dict()
if self.location and self.publisher and self.offer and self.sku and self.version: if self.location and self.publisher and self.offer and self.sku and self.version:
self.results['ansible_facts']['azure_vmimages'] = self.get_item() self.results['ansible_facts']['azure_vmimages'] = self.get_item()
elif self.location and self.publisher and self.offer and self.sku: elif self.location and self.publisher and self.offer and self.sku:

@ -280,9 +280,6 @@ class AzureRMVirtualMachineScaleSetInfo(AzureRMModuleBase):
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict(
azure_vmss=[]
)
) )
self.name = None self.name = None
@ -308,20 +305,14 @@ class AzureRMVirtualMachineScaleSetInfo(AzureRMModuleBase):
if self.name and not self.resource_group: if self.name and not self.resource_group:
self.fail("Parameter error: resource group required when filtering by name.") self.fail("Parameter error: resource group required when filtering by name.")
if is_old_facts:
if self.name:
self.results['ansible_facts']['azure_vmss'] = self.get_item()
else:
self.results['ansible_facts']['azure_vmss'] = self.list_items()
else:
if self.name: if self.name:
self.results['vmss'] = self.get_item() result = self.get_item()
else: else:
self.results['vmss'] = self.list_items() result = self.list_items()
if self.format == 'curated': if self.format == 'curated':
for index in range(len(self.results['ansible_facts']['azure_vmss'])): for index in range(len(result)):
vmss = self.results['ansible_facts']['azure_vmss'][index] vmss = result[index]
subnet_name = None subnet_name = None
load_balancer_name = None load_balancer_name = None
virtual_network_name = None virtual_network_name = None
@ -385,13 +376,18 @@ class AzureRMVirtualMachineScaleSetInfo(AzureRMModuleBase):
'tags': vmss.get('tags') 'tags': vmss.get('tags')
} }
self.results['ansible_facts']['azure_vmss'][index] = updated result[index] = updated
if is_old_facts:
self.results['ansible_facts'] = {
'azure_vmss': result
}
if self.format == 'curated':
# proper result format we want to support in the future # proper result format we want to support in the future
# dropping 'ansible_facts' and shorter name 'vmss' # dropping 'ansible_facts' and shorter name 'vmss'
self.results['vmss'] = self.results['ansible_facts']['azure_vmss'] self.results['vmss'] = result
if not is_old_facts: else:
self.results.pop('ansible_facts', None) self.results['vmss'] = result
return self.results return self.results

@ -214,7 +214,6 @@ class AzureRMNetworkInterfaceInfo(AzureRMModuleBase):
self.results = dict( self.results = dict(
changed=False, changed=False,
ansible_facts=dict(azure_virtualnetworks=[]),
virtualnetworks=[] virtualnetworks=[]
) )
@ -242,7 +241,9 @@ class AzureRMNetworkInterfaceInfo(AzureRMModuleBase):
results = self.list_items() results = self.list_items()
if is_old_facts: if is_old_facts:
self.results['ansible_facts']['azure_virtualnetworks'] = self.serialize(results) self.results['ansible_facts'] = {
'azure_virtualnetworks': self.serialize(results)
}
self.results['virtualnetworks'] = self.curated(results) self.results['virtualnetworks'] = self.curated(results)
return self.results return self.results

Loading…
Cancel
Save