By carsoncole
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
vars:
do_token: xxxx
droplets:
- droplet-one
- droplet-two
tasks:
- name: ensure key exists at DigitalOcean
digital_ocean: >
state=present
command=ssh
name=demo
ssh_pub_key={{ lookup('file', '~/.ssh/id_rsa.pub') }}
api_token={{ do_token }}
register: demo
- name: ensure droplets exist
digital_ocean:
state: present
command: droplet
name: "{{item}}"
unique_name: yes
size_id: 512mb
region_id: sfo1
image_id: 15764687
private_networking: "yes"
ssh_key_ids: "{{ demo.ssh_key.id }}"
api_token: "{{ do_token }}"
with_items: "{{droplets}}"
register: droplet_details
- debug: msg="IP is {{ item.droplet.ip_address }}"
with_items: droplet_details.results
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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 :)
Hi,
One thing I noticed that would cause this is that your unique_name: yes statement should instead be unique_name=yes to match the tutorial:
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.