How to extract specific value from register output

597 views
Skip to first unread message

dudu.c...@gmail.com

unread,
Mar 8, 2021, 10:57:42 AM3/8/21
to Ansible Project

How to extract a specific value from register output:

From the below register output I’m trying to extract the  path value with no luck, I have tried few options but still, I’m falling

 

- debug:
    msg: "{{ file_name }}" - debug:
    msg: "{{ file_name.results.path }}"  - debug:
    msg: "{{ file_name.path }}"

 

File_name register output

 

    "msg": {

        "changed": false,

        "msg": "All items completed",

        "results": [

            {

                "ansible_loop_var": "item",

                "changed": false,

                "checksum": "45823e35872e278fe781a182aa50abcd92d2df62",

                "dest": "/data/nifi-deployment/file_32.tar.gz",

                "diff": {

                    "after": {

                        "path": "/data/nifi-deployment/file_32.tar.gz"

                    },

                    "before": {

                        "path": "/data/nifi-deployment/file_32.tar.gz"

                    }

                },

                "failed": false,

                "gid": 0,

                "group": "root",

                "invocation": {

                    "module_args": {

                        "_diff_peek": null,

                        "_original_basename": " file_32.tar.gz ",

                        "access_time": null,

                        "access_time_format": "%Y%m%d%H%M.%S",

                        "attributes": null,

                        "backup": null,

                        "content": null,

                        "delimiter": null,

                        "dest": "/data/nifi-deployment",

                        "directory_mode": null,

                        "follow": true,

                        "force": true,

                        "group": null,

                        "mode": null,

                        "modification_time": null,

                        "modification_time_format": "%Y%m%d%H%M.%S",

                        "owner": null,

                        "path": "/data/nifi-deployment/file_32.tar.gz",

                        "recurse": false,

                        "regexp": null,

                        "remote_src": null,

                        "selevel": null,

                        "serole": null,

                        "setype": null,

                        "seuser": null,

                        "src": null,

                        "state": "file",

                        "unsafe_writes": null

                    }

                },

                "item": "/repo/file_32.tar.gz ",

                "mode": "0644",

                "owner": "root",

                "path": "/data/nifi-deployment/file_32.tar.gz",

                "secontext": "system_u:object_r:default_t:s0",

                "size": 4938,

                "state": "file",

                "uid": 0

            }

        ]

    }

}

Nuno Jordão

unread,
Mar 8, 2021, 11:22:26 AM3/8/21
to ansible...@googlegroups.com
Hello,

It's inside a "results" list. The result of a loop?
In that case you need: {{ file_name.results[0].path }} to get the first element of the "results" list.
If you have more, you need a loop to iterate it.

Nuno Jordão

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bdbb05c9-e58f-410d-8181-868ab76a5b11n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages