summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@ansible.com>2015-10-12 11:35:43 -0400
committerBrian Coca <bcoca@ansible.com>2015-10-12 11:35:43 -0400
commit2c24fbbd6a6ac04acb50521c53a2744e1b2a5397 (patch)
tree1a43a10a701432888cd6df4538c398a4098cd18d
parentf5f3bf06e4b0adc4a91f25065a97d0976eb76f30 (diff)
parentbdd3ae9d6154630f71c94443ef3fe1d06d4f6585 (diff)
downloadansible-2c24fbbd6a6ac04acb50521c53a2744e1b2a5397.tar.gz
Merge pull request #12618 from AdThrive/devel
Added an option to use the private network IP address for DigitalOcean dynamic inventory
-rw-r--r--contrib/inventory/digital_ocean.ini4
-rwxr-xr-xcontrib/inventory/digital_ocean.py8
2 files changed, 10 insertions, 2 deletions
diff --git a/contrib/inventory/digital_ocean.ini b/contrib/inventory/digital_ocean.ini
index 021899731c..01afe33968 100644
--- a/contrib/inventory/digital_ocean.ini
+++ b/contrib/inventory/digital_ocean.ini
@@ -22,3 +22,7 @@ cache_path = /tmp
# seconds, a new API call will be made, and the cache file will be updated.
#
cache_max_age = 300
+
+# Use the private network IP address instead of the public when available.
+#
+use_private_network = False
diff --git a/contrib/inventory/digital_ocean.py b/contrib/inventory/digital_ocean.py
index 97e6ea1183..1c0ef68cff 100755
--- a/contrib/inventory/digital_ocean.py
+++ b/contrib/inventory/digital_ocean.py
@@ -167,6 +167,7 @@ class DigitalOceanInventory(object):
# Define defaults
self.cache_path = '.'
self.cache_max_age = 0
+ self.use_private_network = False
# Read settings, environment variables, and CLI arguments
self.read_settings()
@@ -256,6 +257,9 @@ or environment variables (DO_API_TOKEN)''')
if config.has_option('digital_ocean', 'cache_max_age'):
self.cache_max_age = config.getint('digital_ocean', 'cache_max_age')
+ # Private IP Address
+ if config.has_option('digital_ocean', 'use_private_network'):
+ self.use_private_network = config.get('digital_ocean', 'use_private_network')
def read_environment(self):
''' Reads the settings from environment variables '''
@@ -345,8 +349,8 @@ or environment variables (DO_API_TOKEN)''')
# add all droplets by id and name
for droplet in self.data['droplets']:
- #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
- if 'private_networking' in droplet['features']:
+ #when using private_networking, the API reports the private one in "ip_address".
+ if 'private_networking' in droplet['features'] and not self.use_private_network:
for net in droplet['networks']['v4']:
if net['type']=='public':
dest=net['ip_address']