|
|
@ -429,6 +429,21 @@ class DigitalOceanInventory(object):
|
|
|
|
self.data['tags'] = self.manager.all_tags()
|
|
|
|
self.data['tags'] = self.manager.all_tags()
|
|
|
|
self.cache_refreshed = True
|
|
|
|
self.cache_refreshed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_inventory_group(self, key):
|
|
|
|
|
|
|
|
""" Method to create group dict """
|
|
|
|
|
|
|
|
host_dict = {'hosts': [], 'vars': {}}
|
|
|
|
|
|
|
|
self.inventory[key] = host_dict
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_host(self, group, host):
|
|
|
|
|
|
|
|
""" Helper method to reduce host duplication """
|
|
|
|
|
|
|
|
if group not in self.inventory:
|
|
|
|
|
|
|
|
self.add_inventory_group(group)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if host not in self.inventory[group]['hosts']:
|
|
|
|
|
|
|
|
self.inventory[group]['hosts'].append(host)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def build_inventory(self):
|
|
|
|
def build_inventory(self):
|
|
|
|
""" Build Ansible inventory of droplets """
|
|
|
|
""" Build Ansible inventory of droplets """
|
|
|
|
self.inventory = {
|
|
|
|
self.inventory = {
|
|
|
@ -449,8 +464,9 @@ class DigitalOceanInventory(object):
|
|
|
|
|
|
|
|
|
|
|
|
self.inventory['all']['hosts'].append(dest)
|
|
|
|
self.inventory['all']['hosts'].append(dest)
|
|
|
|
|
|
|
|
|
|
|
|
self.inventory[droplet['id']] = [dest]
|
|
|
|
self.add_host(droplet['id'], dest)
|
|
|
|
self.inventory[droplet['name']] = [dest]
|
|
|
|
|
|
|
|
|
|
|
|
self.add_host(droplet['name'], dest)
|
|
|
|
|
|
|
|
|
|
|
|
# groups that are always present
|
|
|
|
# groups that are always present
|
|
|
|
for group in ('digital_ocean',
|
|
|
|
for group in ('digital_ocean',
|
|
|
@ -459,24 +475,18 @@ class DigitalOceanInventory(object):
|
|
|
|
'size_' + droplet['size']['slug'],
|
|
|
|
'size_' + droplet['size']['slug'],
|
|
|
|
'distro_' + DigitalOceanInventory.to_safe(droplet['image']['distribution']),
|
|
|
|
'distro_' + DigitalOceanInventory.to_safe(droplet['image']['distribution']),
|
|
|
|
'status_' + droplet['status']):
|
|
|
|
'status_' + droplet['status']):
|
|
|
|
if group not in self.inventory:
|
|
|
|
self.add_host(group, dest)
|
|
|
|
self.inventory[group] = {'hosts': [], 'vars': {}}
|
|
|
|
|
|
|
|
self.inventory[group]['hosts'].append(dest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# groups that are not always present
|
|
|
|
# groups that are not always present
|
|
|
|
for group in (droplet['image']['slug'],
|
|
|
|
for group in (droplet['image']['slug'],
|
|
|
|
droplet['image']['name']):
|
|
|
|
droplet['image']['name']):
|
|
|
|
if group:
|
|
|
|
if group:
|
|
|
|
image = 'image_' + DigitalOceanInventory.to_safe(group)
|
|
|
|
image = 'image_' + DigitalOceanInventory.to_safe(group)
|
|
|
|
if image not in self.inventory:
|
|
|
|
self.add_host(image, dest)
|
|
|
|
self.inventory[image] = {'hosts': [], 'vars': {}}
|
|
|
|
|
|
|
|
self.inventory[image]['hosts'].append(dest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if droplet['tags']:
|
|
|
|
if droplet['tags']:
|
|
|
|
for tag in droplet['tags']:
|
|
|
|
for tag in droplet['tags']:
|
|
|
|
if tag not in self.inventory:
|
|
|
|
self.add_host(tag, dest)
|
|
|
|
self.inventory[tag] = {'hosts': [], 'vars': {}}
|
|
|
|
|
|
|
|
self.inventory[tag]['hosts'].append(dest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# hostvars
|
|
|
|
# hostvars
|
|
|
|
info = self.do_namespace(droplet)
|
|
|
|
info = self.do_namespace(droplet)
|
|
|
|