Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement documented but unimplemented use_private_network INI config option. #45

Merged
merged 3 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/45-fix-use_private_network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- digital_ocean inventory script - implement unimplemented ``use_private_network`` option
and register missing ``do_ip_address``, ``do_private_ip_address``
host vars (https://github.com/ansible-collections/community.digitalocean/pull/45/files).
24 changes: 14 additions & 10 deletions scripts/inventory/digital_ocean.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,19 @@ def build_inventory(self):
for droplet in self.data['droplets']:
for net in droplet['networks']['v4']:
if net['type'] == 'public':
dest = net['ip_address']
else:
continue
droplet['ip_address'] = net['ip_address']
elif net['type'] == 'private':
droplet['private_ip_address'] = net['ip_address']

self.inventory['all']['hosts'].append(dest)
host_indentifier = droplet['ip_address']
if self.use_private_network and droplet['private_ip_address']:
host_indentifier = droplet['private_ip_address']

self.add_host(droplet['id'], dest)
self.inventory['all']['hosts'].append(host_indentifier)

self.add_host(droplet['name'], dest)
self.add_host(droplet['id'], host_indentifier)

self.add_host(droplet['name'], host_indentifier)

# groups that are always present
for group in ('digital_ocean',
Expand All @@ -462,22 +466,22 @@ def build_inventory(self):
'size_' + droplet['size']['slug'],
'distro_' + DigitalOceanInventory.to_safe(droplet['image']['distribution']),
'status_' + droplet['status']):
self.add_host(group, dest)
self.add_host(group, host_indentifier)

# groups that are not always present
for group in (droplet['image']['slug'],
droplet['image']['name']):
if group:
image = 'image_' + DigitalOceanInventory.to_safe(group)
self.add_host(image, dest)
self.add_host(image, host_indentifier)

if droplet['tags']:
for tag in droplet['tags']:
self.add_host(tag, dest)
self.add_host(tag, host_indentifier)

# hostvars
info = self.do_namespace(droplet)
self.inventory['_meta']['hostvars'][dest] = info
self.inventory['_meta']['hostvars'][host_indentifier] = info

def load_droplet_variables_for_host(self):
""" Generate a JSON response to a --host call """
Expand Down