How to have unique_name with Ansible and DO?

April 21, 2016 634 views
Ansible Configuration Management Ubuntu

Trying to get my Ansible playbook to keep unique_names, but I can't get this feature to work. Followed the tutorial on Ansible with DO 2.0 Api, but every time I run my playbook, totally new droplets are created with the SAME names!

Here's my playbook, which otherwise works fine.

- hosts: digitalocean

    do_token: xxxx
    - droplet-one
    - droplet-two

  - name: ensure key exists at DigitalOcean
    digital_ocean: >
      ssh_pub_key={{ lookup('file', '~/.ssh/') }}
      api_token={{ do_token }}
    register: demo

  - name: ensure droplets exist
      state: present
      command: droplet
      name: "{{item}}"
      unique_name: yes
      size_id: 512mb
      region_id: sfo1
      image_id: 15764687
      private_networking: "yes"
      ssh_key_ids: "{{ }}"
      api_token: "{{ do_token }}"
    with_items: "{{droplets}}"
    register: droplet_details

  - debug: msg="IP is {{ item.droplet.ip_address }}"
    with_items: droplet_details.results
1 comment
  • Using dopy 0.3.5, the private networking option also does not work, however will work if you use dopy 0.3.6.

    dopy 0.3.7 is broken and will cause a

    NameError: name 'DoError' is not defined
1 Answer


One thing I noticed that would cause this is that your uniquename: yes statement should instead be uniquename=yes to match the tutorial:

  • name: ensure droplet one exists digitalocean: > state=present command=droplet name=droplet-one uniquename=yes size_id=512mb Additionally, it's likely the dual name declarations will cause an issue - It looks like you will need to use either - name: ensure key exists at DigitalOcean or - name: ensure droplets exist for this to work as expected.
  • Hi Brook,
    Thanks for helping.

    Either format seems to work (and frankly is easier to read using key:value), and in fact it otherwise works fine with no errors, with all of the set values, for size, region, image_id etc. Just to be sure, I converted the format back to the tutorial and it was no different: every time I ran it, another droplet is created with the same name.

        - name: Ensure droplet exists
          digital_ocean: >
            ssh_key_ids="{{ }}"
            api_token="{{ do_token }}"
          register: droplet_details

    As for your second point, my 'names' for the two tasks are different, so there shouldn't be any issues? Maybe I'm not understanding.

    - name: ensure key exists at DigitalOcean
    - name: Ensure droplet exists

    I'm wondering if its my version of Ansible at

Have another answer? Share your knowledge.