Digital ocean dynamic inventory - just plain old barely works

560 views
Skip to first unread message

Ryan Rawson

unread,
Feb 5, 2015, 1:02:02 AM2/5/15
to ansible...@googlegroups.com
So I am doing a digital ocean thing.  I saw the dynamic inventory scripts and thought my problems were solved.  But turns out, it only covers the simplest case and doesn't help you further.

The background here is I'm doing a little bit of a hbase thing.  So I have created some hosts using the digital ocean commands, but first I had to fix the private networking bug (https://github.com/ansible/ansible-modules-core/pull/677)

So I create my hosts with a standalone playbook:
---
- hosts: localhost
  vars:
    ssh_keys: 1234
  connection: local
  tasks:
  - name: create droplets
    digital_ocean: >
      state=present
      wait=no
      private_networking=true
      command=droplet
      name={{ item }}
      unique_name=yes
      size_id=65
      region_id=8
      ssh_key_ids="{{ ssh_keys }}"
      image_id=9801950
    with_items:
      - hbase0
      - hbase1
      - hbase2
      - hbase3
      - hbase4
      - hbase5
      - hbase6
      - hbase7
      - hbase8

And this seems to work.  So I have 9 hosts, hooray!

I can even do:
ansible hbase0 -i digital_ocean.py -m ping

and i can ping just that 1 host

and I can do:
ansible all -i digital_ocean.py -m ping

and that works.  And that's great.

But now I need to do groups.  Since this is HBase, we need some hosts to be slightly different than other hosts.  Pretty standard ansible stuff.

So I will:
mkdir inventory
cp digital_ocean.py inventory
vim inventory/groups

And put stuff in this new 'groups' file.

Except that it's nearly impossible to do anything smart here.

Some facts:
- you can't use 'host names' -- do_name, or ansible_hostname in the facts
- you can't use globs: hbase[0:8]
- you can't really identify these 9 servers via anything other than their size, or their image id.  No tags - digital ocean's fault here, but still.
- you might be able to use raw IP addresses, but I don't know which IP is hbase0. 

So I gave up on digital_ocean.py.  I now generate a file i can paste into /etc/hosts, and use raw names hbase0, hbase1, etc, in a static file.  Basically I use dynamic inventory for generating the data I use to drive static hosts.

I have tried googling, asking irc.  As far as I can tell, if anyone else has a similar problem, google doesn't know.

In the mean time, I am back using static inventory.

Shawn Adams

unread,
Feb 18, 2015, 2:51:37 PM2/18/15
to ansible...@googlegroups.com
Ryan,

I am facing the same issue as you. In your case you can actually reference your hosts from a play like this :

hosts: hbase0:hbase1:hbase2 (and so on)

Which is not ideal but it does "work". In my case I need to create servers in DO and I need to reference them with groups like "prod" and "prod-appname". The solution I came up with involves making changes to the digital_ocean.py inventory script. The changes were quite simple and you can follow a similar approach. 


In your case you would  do something like this: 

if the droplet['name'].startswith('hbase'):
    self.push(self.inventory, "hbase", dest)
Reply all
Reply to author
Forward
0 new messages