register variable

50 views
Skip to first unread message

Nico K.

unread,
Apr 9, 2015, 4:43:02 AM4/9/15
to ansible...@googlegroups.com
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.


Nico K.

unread,
Apr 9, 2015, 5:08:32 AM4/9/15
to ansible...@googlegroups.com
The "fix" is to change:

set_fact: x=y

to
set_fact:
  x: y

No idea why.. but it works

Brian Coca

unread,
Apr 9, 2015, 4:07:28 PM4/9/15
to ansible...@googlegroups.com
different parsers, the x=y is a custom ansible module parameter
parser, x: y is just yaml.

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages