1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

add missing hostvars properties in azure_rm.py inventory (#53046)

* add missing hostvars properties

* fix lint

* fix lint

* add security group

* fix lint
This commit is contained in:
Yunge Zhu 2019-03-07 02:55:43 +08:00 committed by Matt Davis
parent b090b57eac
commit 71042e1a79

View file

@ -162,6 +162,7 @@ from itertools import chain
from msrest import ServiceClient, Serializer, Deserializer from msrest import ServiceClient, Serializer, Deserializer
from msrestazure import AzureConfiguration from msrestazure import AzureConfiguration
from msrestazure.polling.arm_polling import ARMPolling from msrestazure.polling.arm_polling import ARMPolling
from msrestazure.tools import parse_resource_id
class AzureRMRestConfiguration(AzureConfiguration): class AzureRMRestConfiguration(AzureConfiguration):
@ -499,7 +500,10 @@ class AzureHost(object):
vmss=dict( vmss=dict(
id=self._vmss['id'], id=self._vmss['id'],
name=self._vmss['name'], name=self._vmss['name'],
) if self._vmss else {} ) if self._vmss else {},
virtual_machine_size=self._vm_model['properties']['hardwareProfile']['vmSize'] if self._vm_model['properties'].get('hardwareProfile') else None,
plan=self._vm_model['properties']['plan']['name'] if self._vm_model['properties'].get('plan') else None,
resource_group=parse_resource_id(self._vm_model['id']).get('resource_group').lower()
) )
# set nic-related values from the primary NIC first # set nic-related values from the primary NIC first
@ -511,12 +515,48 @@ class AzureHost(object):
new_hostvars['private_ipv4_addresses'].append(private_ip) new_hostvars['private_ipv4_addresses'].append(private_ip)
pip_id = ipc['properties'].get('publicIPAddress', {}).get('id') pip_id = ipc['properties'].get('publicIPAddress', {}).get('id')
if pip_id: if pip_id:
new_hostvars['public_ip_id'] = pip_id
pip = nic.public_ips[pip_id] pip = nic.public_ips[pip_id]
new_hostvars['public_ip_name'] = pip._pip_model['name']
new_hostvars['public_ipv4_addresses'].append(pip._pip_model['properties'].get('ipAddress', None)) new_hostvars['public_ipv4_addresses'].append(pip._pip_model['properties'].get('ipAddress', None))
pip_fqdn = pip._pip_model['properties'].get('dnsSettings', {}).get('fqdn') pip_fqdn = pip._pip_model['properties'].get('dnsSettings', {}).get('fqdn')
if pip_fqdn: if pip_fqdn:
new_hostvars['public_dns_hostnames'].append(pip_fqdn) new_hostvars['public_dns_hostnames'].append(pip_fqdn)
new_hostvars['mac_address'] = nic._nic_model['properties'].get('macAddress')
new_hostvars['network_interface'] = nic._nic_model['name']
new_hostvars['network_interface_id'] = nic._nic_model['id']
new_hostvars['security_group_id'] = nic._nic_model['properties']['networkSecurityGroup']['id'] \
if nic._nic_model['properties'].get('networkSecurityGroup') else None
new_hostvars['security_group'] = parse_resource_id(new_hostvars['security_group_id'])['resource_name'] \
if nic._nic_model['properties'].get('networkSecurityGroup') else None
# set image and os_disk
new_hostvars['image'] = {}
new_hostvars['os_disk'] = {}
storageProfile = self._vm_model['properties'].get('storageProfile')
if storageProfile:
imageReference = storageProfile.get('imageReference')
if imageReference:
if imageReference.get('publisher'):
new_hostvars['image'] = dict(
sku=imageReference.get('sku'),
publisher=imageReference.get('publisher'),
version=imageReference.get('version'),
offer=imageReference.get('offer')
)
elif imageReference.get('id'):
new_hostvars['image'] = dict(
id=imageReference.get('id')
)
osDisk = storageProfile.get('osDisk')
new_hostvars['os_disk'] = dict(
name=osDisk.get('name'),
operating_system_type=osDisk.get('osType').lower() if osDisk.get('osType') else None
)
self._hostvars = new_hostvars self._hostvars = new_hostvars
return self._hostvars return self._hostvars