Register and with_dict / with_items

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:

ssh_keys.results.macosx.ssh_key.id

Thanks,
Akos Vandra

If there is a better solution to the problem, i’m open to ideas…