# register variable

**URL:** <https://forum.ansible.com/t/register-variable/17938>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [April 9, 2015, 8:43am UTC](https://forum.ansible.com/t/register-variable/17938 "2015-04-09T08:43:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [April 9, 2015, 8:43am UTC](https://forum.ansible.com/t/register-variable/17938/1 "2015-04-09T08:43:02Z")

</div>

Hi,

I’m trying to register the output of a command which returns json.  
When I do this as a standalone task (not role) it works fine, for example:

- name: x  
hosts: localhost  
tasks:
- shell: aws iam list-server-certificates  
register: y
- set\_fact:  
test: “{{ y.stdout }}”
- debug: msg=“{{ item.Arn }}”  
with\_items: test.ServerCertficateMetadataList

Will correctly report the Arn for all my certificates, however, when I perform the same action in a role:

- name: x  
shell: aws iam list-server-certificates  
register: output

- name: y  
set\_fact: json=“{{ output.stdout }}”

- debug: msg=“{{ json }}”

- debug: msg=“{{ item }}”  
with\_items: json.ServerCertificateMetadataList

it fails with the following message:

debug msg=“{{ json }}”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: "{u’ServerCertificateMetadataList’: [{u’ServerCertificateId’: …

debug msg=“{{ item }}”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> (item=json.ServerCertificateMetadataList) =\> {  
“item”: “json.ServerCertificateMetadataList”,  
“msg”: “json.ServerCertificateMetadataList”  
}

Differences in debug output between the task and the role:

tasks: “msg”: "{‘ServerCertificateMetadataList’: [{‘ServerCertificateId’:  
role: “msg”: "{u’ServerCertificateMetadataList’: [{u’ServerCertificateId’:

Hope someone can help.

Thanks,  
Nico.

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [April 9, 2015, 9:08am UTC](https://forum.ansible.com/t/register-variable/17938/2 "2015-04-09T09:08:32Z")

</div>

The “fix” is to change:

set\_fact: x=y

to  
set\_fact:  
x: y

No idea why… but it works

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 9, 2015, 8:07pm UTC](https://forum.ansible.com/t/register-variable/17938/3 "2015-04-09T20:07:25Z")

</div>

different parsers, the x=y is a custom ansible module parameter  
parser, x: y is just yaml.
