Skip to content

Commit 2c24fbb

Browse files
committedOct 12, 2015
Merge pull request ansible#12618 from AdThrive/devel
Added an option to use the private network IP address for DigitalOcean dynamic inventory
2 parents f5f3bf0 + bdd3ae9 commit 2c24fbb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

‎contrib/inventory/digital_ocean.ini

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ cache_path = /tmp
2222
# seconds, a new API call will be made, and the cache file will be updated.
2323
#
2424
cache_max_age = 300
25+
26+
# Use the private network IP address instead of the public when available.
27+
#
28+
use_private_network = False

‎contrib/inventory/digital_ocean.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def __init__(self):
167167
# Define defaults
168168
self.cache_path = '.'
169169
self.cache_max_age = 0
170+
self.use_private_network = False
170171

171172
# Read settings, environment variables, and CLI arguments
172173
self.read_settings()
@@ -256,6 +257,9 @@ def read_settings(self):
256257
if config.has_option('digital_ocean', 'cache_max_age'):
257258
self.cache_max_age = config.getint('digital_ocean', 'cache_max_age')
258259

260+
# Private IP Address
261+
if config.has_option('digital_ocean', 'use_private_network'):
262+
self.use_private_network = config.get('digital_ocean', 'use_private_network')
259263

260264
def read_environment(self):
261265
''' Reads the settings from environment variables '''
@@ -345,8 +349,8 @@ def build_inventory(self):
345349

346350
# add all droplets by id and name
347351
for droplet in self.data['droplets']:
348-
#when using private_networking, the API reports the private one in "ip_address", which is useless. We need the public one for Ansible to work
349-
if 'private_networking' in droplet['features']:
352+
#when using private_networking, the API reports the private one in "ip_address".
353+
if 'private_networking' in droplet['features'] and not self.use_private_network:
350354
for net in droplet['networks']['v4']:
351355
if net['type']=='public':
352356
dest=net['ip_address']

0 commit comments

Comments
 (0)
Please sign in to comment.