How to have unique_name with Ansible and DO?

Posted April 21, 2016 3.9k views
UbuntuConfiguration ManagementAnsible

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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers


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

I had the same issue. Downgrading ansible to version 2.0 worked for me:

sudo pip install 'ansible>=2.0,<2.1'

If you then run your playbook you will see the following deprecation warning which points to the actual issue with latest ansible versions:

[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the
 full variable syntax ('{{droplet_details.results}}').
This feature will be removed in a future release. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

Hope that helps somebody :)