Skip to content

Commit

Permalink
[contrib] azure_rm.py add mechanism to force use of private ip as ans…
Browse files Browse the repository at this point in the history
…ible_host (ansible#36109)

Signed-off-by: Sylvain Rabot <[email protected]>
  • Loading branch information
sylr authored and nitzmahone committed May 3, 2018
1 parent 31bfb7b commit 521cc3d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contrib/inventory/azure_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@
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"
Expand Down Expand Up @@ -474,6 +475,7 @@ def __init__(self):
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(
Expand Down Expand Up @@ -649,12 +651,15 @@ def _load_machines(self, machines):
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
Expand Down

0 comments on commit 521cc3d

Please sign in to comment.