register variable

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.

The “fix” is to change:

set_fact: x=y

to
set_fact:
x: y

No idea why… but it works

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