diff options
author | Sylvain Rabot <sylvain@abstraction.fr> | 2018-05-03 02:38:06 +0200 |
---|---|---|
committer | Matt Davis <nitzmahone@users.noreply.github.com> | 2018-05-02 17:38:06 -0700 |
commit | 521cc3d4e6f288eb41f46f74a3969b4c195b66ae (patch) | |
tree | 24e1fa8119920bc0d219b1c88f0f4dcf4adab35d /contrib | |
parent | 31bfb7b563274ad6c12dbcc6c5b5334b3ab4aa7a (diff) | |
download | ansible-521cc3d4e6f288eb41f46f74a3969b4c195b66ae.tar.gz |
[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>
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/inventory/azure_rm.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/contrib/inventory/azure_rm.py b/contrib/inventory/azure_rm.py index d706ccd395..d62e1d2df1 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 |