geerlingguy / geerlingguy/ansible-for-devops

Chapter 9 (DigitalOcean Provisioner): add_hosts task fails due to changes in the DO API

Open
#469 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
9.9k
Forks
3.8k
PR merge metrics
No merged PRs in 30d

Description

In Chapter 9 when setting up the digital ocean provisioner I ran into an issues with the task "Add DigitalOcean hosts to inventory groups." because the jinja template `"{{ item.1.data.ip_address }}"` was failing to return the ip of the droplet.

It turns out this is because DO has changed their api a little bit and now returns a `networks` dict. See the stripped example json below

```json
{
"created_droplets": {
"results": [
{
"data": {
"droplet": {
"name": "a4d.lamp.varnish",
"networks": {
"v4": [
{
"gateway": "yyy.yyy.yyy.yyy",
"ip_address": "yyy.yyy.yyy.yyy",
"netmask": "255.255.240.0",
"type": "private"
},
{
"gateway": "xxx.xxx.xxx.xxx",
"ip_address": "xxx.xxx.xxx.xxx",
"netmask": "255.255.240.0",
"type": "public"
}
],
"v6": []
}
}
}
}
]
}
}
```

I did some digging and came up with the following.

```yaml
- name: Add DO Hosts to inventory groups
add_host:
name: "{{ (item.1.data.droplet.networks.v4 | selectattr('type', 'equalto', 'public') | first).ip_address }}"
```

Edit: I found #457 after making this and it looks like the solution there is more complete and it is indeed not fixed in version 1.14.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with Chapter 9's DigitalOcean provisioner and the “Add DigitalOcean hosts to inventory groups” task; compare it with the more complete solution in issue #457. Confirm the task follows the current networks.v4 public-address shape and verify the chapter's provisioning example.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, yaml
Domain
cloud, devops, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.