Hello Everyone

I have been using Ansible for about a year now and I can't wrap my head 
around on idea of "registered variables"
I bought books, read online docs and looked at examples... but I still 
can't use this important future properly.

Let me give you a example:

I want to find files that are older than 7 days:

- name: Find backups that are older than 7 days
  find: paths="/db-backups" age="7d"
  register: list_of_db_backups

and I want to delete the files that I have found:

- name: Cleanup backups that are older than 7 days
  file:
    name: "{{ item.path }}"
    state: absent
  with_items: list_of_db_backups.files


and I get error right away saying that "the field 'args' has an invalid 
value, which appears to include a variable that is undefined. The error 
was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
'path'"

To be able to understand why ansible says *object has no attribute "path"*, 
I add a debug line to my playbook:

- debug: var=list_of_db_backups


and I get this result:

TASK [ServerSetup/dev-mysql : debug] 
*******************************************
ok: [db] => {
    "changed": false, 
    "list_of_db_backups": {
        "changed": false, 
        "examined": 9, 
        "files": [
            {
                "atime": 1493059112.0, 
                "ctime": 1493059112.0, 
                "dev": 28, 
                "gid": 1000, 
                "inode": 136, 
                "isblk": false, 
                "ischr": false, 
                "isdir": false, 
                "isfifo": false, 
                "isgid": false, 
                "islnk": false, 
                "isreg": true, 
                "issock": false, 
                "isuid": false, 
                "mode": "0644", 
                "mtime": 1493059112.0, 
                "nlink": 1, 
                "path": "/db-backups/dev-2017-04-24T18:38:30Z.sql", 
                "rgrp": true, 
                "roth": true, 
                "rusr": true, 
                "size": 397954, 
                "uid": 1000, 
                "wgrp": false, 
                "woth": false, 
                "wusr": true, 
                "xgrp": false, 
                "xoth": false, 
                "xusr": false
            }
        ], 
        "matched": 1, 
        "msg": ""
    }
}


so clearly there is a variable named "path"

What am I doing wrong here? Can someone please clarify? 
This is really important for me to take my ansible skills to the next level.

thank you kindly.





-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fe46947d-896d-406d-a265-3a42da21e28d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to