[contrib] azure_rm.py add mechanism to force use of private ip as ansible_host (#36109)

Signed-off-by: Sylvain Rabot <s.rabot@lectra.com>
pull/39649/head
Sylvain Rabot 7 years ago committed by Matt Davis
parent 31bfb7b563
commit 521cc3d4e6

@ -239,7 +239,8 @@ AZURE_CONFIG_SETTINGS = dict(
group_by_resource_group='AZURE_GROUP_BY_RESOURCE_GROUP', group_by_resource_group='AZURE_GROUP_BY_RESOURCE_GROUP',
group_by_location='AZURE_GROUP_BY_LOCATION', group_by_location='AZURE_GROUP_BY_LOCATION',
group_by_security_group='AZURE_GROUP_BY_SECURITY_GROUP', group_by_security_group='AZURE_GROUP_BY_SECURITY_GROUP',
group_by_tag='AZURE_GROUP_BY_TAG' group_by_tag='AZURE_GROUP_BY_TAG',
use_private_ip='AZURE_USE_PRIVATE_IP'
) )
AZURE_MIN_VERSION = "2.0.0" AZURE_MIN_VERSION = "2.0.0"
@ -474,6 +475,7 @@ class AzureInventory(object):
self.group_by_security_group = True self.group_by_security_group = True
self.group_by_tag = True self.group_by_tag = True
self.include_powerstate = True self.include_powerstate = True
self.use_private_ip = False
self._inventory = dict( self._inventory = dict(
_meta=dict( _meta=dict(
@ -649,12 +651,15 @@ class AzureInventory(object):
for ip_config in network_interface.ip_configurations: for ip_config in network_interface.ip_configurations:
host_vars['private_ip'] = ip_config.private_ip_address host_vars['private_ip'] = ip_config.private_ip_address
host_vars['private_ip_alloc_method'] = ip_config.private_ip_allocation_method host_vars['private_ip_alloc_method'] = ip_config.private_ip_allocation_method
if self.use_private_ip:
host_vars['ansible_host'] = ip_config.private_ip_address
if ip_config.public_ip_address: if ip_config.public_ip_address:
public_ip_reference = self._parse_ref_id(ip_config.public_ip_address.id) public_ip_reference = self._parse_ref_id(ip_config.public_ip_address.id)
public_ip_address = self._network_client.public_ip_addresses.get( public_ip_address = self._network_client.public_ip_addresses.get(
public_ip_reference['resourceGroups'], public_ip_reference['resourceGroups'],
public_ip_reference['publicIPAddresses']) public_ip_reference['publicIPAddresses'])
host_vars['ansible_host'] = public_ip_address.ip_address if not self.use_private_ip:
host_vars['ansible_host'] = public_ip_address.ip_address
host_vars['public_ip'] = public_ip_address.ip_address host_vars['public_ip'] = public_ip_address.ip_address
host_vars['public_ip_name'] = public_ip_address.name host_vars['public_ip_name'] = public_ip_address.name
host_vars['public_ip_alloc_method'] = public_ip_address.public_ip_allocation_method host_vars['public_ip_alloc_method'] = public_ip_address.public_ip_allocation_method

Loading…
Cancel
Save