# Register and with\_dict / with\_items

**URL:** <https://forum.ansible.com/t/register-and-with-dict-with-items/17138>\
**Category:** Ansible Project\
**Created:** [December 23, 2014, 10:13pm UTC](https://forum.ansible.com/t/register-and-with-dict-with-items/17138 "2014-12-23T22:13:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akos\_Vandra](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Akos\_Vandra](https://forum.ansible.com/u/Akos_Vandra)\
**Post date:** [December 23, 2014, 10:13pm UTC](https://forum.ansible.com/t/register-and-with-dict-with-items/17138/1 "2014-12-23T22:13:52Z")

</div>

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](http://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](http://ssh_keys.results.macosx.ssh_key.id)

Thanks,  
Akos Vandra

---

<div class="post-metadata">

**Author:** ![Akos\_Vandra](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Akos\_Vandra](https://forum.ansible.com/u/Akos_Vandra)\
**Post date:** [December 29, 2014, 5:38pm UTC](https://forum.ansible.com/t/register-and-with-dict-with-items/17138/2 "2014-12-29T17:38:40Z")

</div>

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