Register and with_dict / with_items

319 views
Skip to first unread message

Akos Vandra

unread,
Dec 23, 2014, 5:13:57 PM12/23/14
to ansible-project
Hello!

I would like to upload ssh keys to digitalocean, and register their ids, like so:

    - digital_ocean_sshkey: state=present "name={{item.value.name}}" "ssh_pub_key={{lookup('file', item.value.file)}}" client_id={{digitalocean_client_id}} api_key={{digitalocean_api_key}}
      register: ssh_keys
      with_dict: keys


I would expect ssh_keys.values to be a map based on the dict keys, but it is an array.

ok: [127.0.0.1] => {
    "ssh_key": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "changed": false,
                "invocation": {
                    "module_args": "state=present \"name=Foo Key\" \"ssh_pub_key=***\" client_id=*** api_key=***",
                    "module_name": "digital_ocean_sshkey"
                },
                "item": {
                    "key": "foo",
                    "value": {
                        "file": "~/.ssh/id_rsa2.pub",
                        "name": "Foo Key"
                    }
                },
                "ssh_key": {
                    "id": 604472,
                    "name": "Foo Key"
                }
            },
            {
                "changed": false,
                "invocation": {
                    "module_args": "state=present \"name=MacBook\" \"ssh_pub_key=***\" client_id=*** api_key=***",
                    "module_name": "digital_ocean_sshkey"
                },
                "item": {
                    "key": "macbook",
                    "value": {
                        "file": "~/.ssh/id_rsa.pub",
                        "name": "MacBook"
                    }
                },
                "ssh_key": {
                    "id": 599365,
                    "name": "MacBook"
                }
            }
        ]
    }
}

Is it possible to transform that array into a map keyed by the dict keys, so that the ssh key ids could be fetched like so:


Thanks,
  Akos Vandra

Akos Vandra

unread,
Dec 29, 2014, 12:38:44 PM12/29/14
to ansible-project
If there is a better solution to the problem, i'm open to ideas...
Reply all
Reply to author
Forward
0 new messages