From 521cc3d4e6f288eb41f46f74a3969b4c195b66ae Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Thu, 3 May 2018 02:38:06 +0200 Subject: [PATCH] [contrib] azure_rm.py add mechanism to force use of private ip as ansible_host (#36109) Signed-off-by: Sylvain Rabot --- contrib/inventory/azure_rm.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/inventory/azure_rm.py b/contrib/inventory/azure_rm.py index d706ccd3958..d62e1d2df1c 100755 --- a/contrib/inventory/azure_rm.py +++ b/contrib/inventory/azure_rm.py @@ -239,7 +239,8 @@ AZURE_CONFIG_SETTINGS = dict( group_by_resource_group='AZURE_GROUP_BY_RESOURCE_GROUP', group_by_location='AZURE_GROUP_BY_LOCATION', 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" @@ -474,6 +475,7 @@ class AzureInventory(object): self.group_by_security_group = True self.group_by_tag = True self.include_powerstate = True + self.use_private_ip = False self._inventory = dict( _meta=dict( @@ -649,12 +651,15 @@ class AzureInventory(object): for ip_config in network_interface.ip_configurations: host_vars['private_ip'] = ip_config.private_ip_address 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: 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_reference['resourceGroups'], 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_name'] = public_ip_address.name host_vars['public_ip_alloc_method'] = public_ip_address.public_ip_allocation_method