how to display sub variables using debug module

62 views
Skip to first unread message

John Veliss

unread,
Jun 28, 2021, 11:19:26 AM6/28/21
to Ansible Project
I am using the win.find module along with the debug module to list files.

  tasks:
  - name: Find ALDM zip files
    ansible.windows.win_find:
      paths: c:\temp
      recurse: no
      patterns: "*.zip"
    register: files_to_copy
  - debug:
      msg: "{{files_to_copy}}"


This is what I get

 "msg": {
        "changed": false,
        "examined": 13,
        "failed": false,
        "files": [
            {
                "attributes": "Archive",
                "checksum": "2ac51252d04aa02addeda5a86270da2a925b13fc",
                "creationtime": 1624860215.3043969,
                "exists": true,
                "extension": ".zip",
                "filename": "xsapagos-xxstestwin-2106280603.zip",
                "hlnk_targets": [],
                "isarchive": true,
                "isdir": false,
                "ishidden": false,
                "isjunction": false,
                "islnk": false,
                "isreadonly": false,
                "isreg": true,
                "isshared": false,
                "lastaccesstime": 1624860215.6950212,
                "lastwritetime": 1624860215.6950212,
                "lnk_source": null,
                "lnk_target": null,
                "nlink": 1,
                "owner": "BUILTIN\\Administrators",
                "path": "C:\\temp\\ xsapagos-xxstestwin-2106280603.zip  ",
                "sharename": null,
                "size": 24556
            },

How can I use debug to output just the filename

as I have tried the below 

- debug:
      msg: "{{files_to_copy.files.filename}}"

But I get --> {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'filename'\n\nThe error appears to be in 

Clint Denham

unread,
Jun 28, 2021, 12:05:56 PM6/28/21
to ansible...@googlegroups.com
Files is a list

 "files": [
  
So you need to reference which entry of the list you want to debug. For example...

files_to_copy.files.0.filename

--
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/269eeeb1-1421-4e5f-896a-9562d67a9dafn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages