digital_ocean module and host_vars

47 views
Skip to first unread message

Jerry Steele

unread,
Jan 5, 2017, 11:07:51 AM1/5/17
to Ansible Project
Hi All,

It looks like I've stumbled across a bug with the digital_ocean module.

I've been following the digital ocean tutorial here, but I want to parameterise as much as possible. I'm building a role, and this is the main tasks.yml:

- hosts: digitalocean
  vars
:
   
- zonomi_api_key: <my zonomi api key>
   
- zonomi_url: http://zonomi.com/app/dns/dyndns.jsp
   
- do_url: <URL of do_droplet>
   
- do_domain: <my domain>
  tasks
:

   
- name: Add droplet
      digital_ocean
: >
        state
=present
        command
=droplet
        name
={{ item.key }}
        size_id
=512mb
        region_id
=ams2
        image_id
={{ item.value.image_id }}
        ssh_key_ids
={{ my_ssh_key.ssh_key.id }}
        unique_name
=yes
      with_dict
: "{{ droplets_up }}"
     
register: my_droplet


   
- debug:
        msg
: {{ my_droplet.droplet.ip_address }

 The host_vars are elsewhere, but I don't believe they're important in this context - the droplet gets created as expected.

However, I get the following error about the "ip_address" var:

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'id'\n\nThe error appears to have been in '/my/path/digitalocean.yml': line 33, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        msg: Droplet details are {{ my_droplet }}\n    - debug:\n      ^ here\n"}

The official docs appear to suggest that this should work, and if I print debug output of "my_droplet" on its own, I get a dump of the variable with all its data (I won't reprint it unless it's required as it would take a while to go through and obfuscate any sensitive data). I would like the ability to pick out certain parts of the var (in this instance, I need the IP in order to publish it to my DNS server..

Thanks

Jerry


Johannes Kastl

unread,
Jan 6, 2017, 3:42:16 PM1/6/17
to ansible...@googlegroups.com
On 05.01.17 17:07 Jerry Steele wrote:

> - debug: msg: {{ my_droplet.droplet.ip_address }

1. You are missing the second closing curly bracket.

2. Does using this help?
- debug: var=my_droplet
- debug: var=my_droplet.droplet
- debug: var=my_droplet.droplet.ip_address

3. Sure you have not mixed up ip and id somewhere:
"The error was: 'dict object' has no attribute 'id'"

What's in "/my/path/digitalocean.yml': line 33, column 7"? Anything
that hits your eye?

Johannes

signature.asc

Simon Wydooghe

unread,
Jan 8, 2017, 7:13:58 AM1/8/17
to Ansible Project
It will also fail if you don't quote the variable.

Use this:

- debug:
    msg
: "{{ my_droplet.droplet.ip_address }}"

Or this:

- debug: msg={{ my_droplet.droplet.ip_address }}

Simon
Reply all
Reply to author
Forward
0 new messages