Question

ansible-droplet returns wrong droplet IP address since 2020-10-01 VCP changes

  • Posted October 13, 2020
  • API

I’ve successfully automated droplet creation and destruction with ansible-droplet for since 2017. However, since 2020-10-01, ansible-droplet registers and returns the internal VPC address from the API’s droplet creation response, not the desired external IP address.

It’s easy to see the problem. When ansible creates the droplet, it uses: - name: “Create Droplet: “{{ droplet_name }}”” digital_ocean: api_token: “{{ do_token }}” command: droplet ssh_key_ids: “{{ ssh_key_on_do.ssh_key.id }}” unique_name: yes state: present name: “{{ droplet_name }}” size_id: “{{ droplet_specs.size }}” region_id: “{{ droplet_specs.region }}” image_id: “{{ droplet_specs.image }}” register: created

And it parses that ‘created’ value for ‘ip_address’ to get the external (eth0) ip address. However, since the VPC change, the ip_address value has been reassigned to the droplet’s VPC private address. There is no distinct key that can be used to call for the droplet’s external IP address.

You can see the issue in this somewhat redacted ‘created’ content:

{u’kernel’: None, u’features’: [u’private_networking’], u’vpc_uuid’: u’bec324ec-dc82-11e8-83ec-3cfdfea9f3f0’, u’image’: {u’status’: u’available’, u’min_disk_size’: 15, u’size_gigabytes’: 2.36, u’name’: u’16.04 (LTS) x64’, u’tags’: [], u’created_at’: u’2020-09-02T23:19:07Z’, u’id’: 69451585, u’regions’: [u’nyc3’, u’nyc1’, u’sfo1’, u’nyc2’, u’ams2’, u’sgp1’, u’lon1’, u’ams3’, u’fra1’, u’tor1’, u’sfo2’, u’blr1’, u’sfo3’], u’public’: True, u’distribution’: u’Ubuntu’, u’type’: u’base’, u’slug’: u’ubuntu-16-04-x64’, u’description’: u’Ubuntu 16.04 x86 image’}, u’disk’: 25, u’networks’: {u’v4’: [{u’type’: u’private’, u’netmask’: u’255.255.0.0’, u’ip_address’: u’10.131.0.2’, u’gateway’: u’<nil>‘}, {u’type’: u’public’, u’netmask’: u’255.255.240.0’, u’ip_address’: u’167.99.81.201’, u’gateway’: u’167.99.80.1’}], u’v6’: []}, u’size’: {u’price_monthly’: 5.0, u’available’: True, u’transfer’: 1.0, u’price_hourly’: 0.00744, u’regions’: [u’ams2’, u’ams3’, u’blr1’, u’fra1’, u’lon1’, u’nyc1’, u’nyc2’, u’nyc3’, u’sfo1’, u’sfo2’, u’sfo3’, u’sgp1’, u’tor1’], u’vcpus’: 1, u’memory’: 1024, u’disk’: 25, u’slug’: u’s-1vcpu-1gb’}, u’backup_ids’: [], u’snapshot_ids’: [], u’id’: 211955088, u’next_backup_window’: None, u’memory’: 1024, u’status’: u’active’, u’tags’: [], u’ip_address’: u’10.131.0.2’, u’volume_ids’: [], u’locked’: False, u’name’: u’laptop’, u’region’: {u’available’: True, u’slug’: u’lon1’, u’features’: [u’private_networking’, u’backups’, u’ipv6’, u’metadata’, u’install_agent’, u’storage’, u’image_transfer’], u’name’: u’London 1’,}, u’size_slug’: u’s-1vcpu-1gb’, u’vcpus’: 1, u’created_at’: u’2020-10-13T17:04:48Z’}

Would it be possible to modify the API response so that it has a unique key for the external IP address?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Answering my own question…

In the ansible-droplet library’s file called ‘create-droplet-playbook.yml’, look for all three references to the droplet’s external IP address. They come in two different formats:

  1. created.droplet.ip_address
  2. ansible_default_ipv4.address

Change both forms to: ‘created.droplet.networks.v4[1].ip_address’

This modifies ‘create-droplet-playbook.yml’ to correctly parse the variable called ‘created’ into which ansible-droplet loads the API response it registers when the droplet is created.