On Ansible 2.3.1.0 this works:

      - name: Identify logs
        find: paths=/var/log/nginx patterns="*.log"
        ignore_errors: true
        register: files_to_delete

      - name: Remove debug file log
        file: path=/tmp/test.log state=absent

      - name: Log matched files
        shell: echo {{ item.path }} /tmp >> /tmp/test.log
        with_items: "{{ files_to_delete.files }}"


It would be nice to be able to do a debug var or msg, but that seems to 
break the loop for some reason. Anyway I can dump the matched log files in 
/tmp/test.log on each server in /tmp/test.log.

I would like to extend the find:

      - name: Identify logs
        find: paths=/var/log/{{ item }} patterns="*.log"
        with_items:
          - nginx
          - apache
          - qmail
          - opensmtp
        ignore_errors: true
        register: files_to_delete


doing a debug: var=files_to_delete I see the following structure:
ok: [server] => {
    "files_to_delete": {
        "changed": false, 
        "msg": "All items completed", 
        "results": [
            {
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "_ansible_parsed": true, 
                "changed": false, 
                "examined": 4, 
                "files": [
                    {
                        "atime": 1501710174.3968189, 
                        "ctime": 1501710167.0451255, 
                        "dev": 51713, 
                        "gid": 0, 
                        "inode": 1307247, 
                        "isblk": false, 
                        "ischr": false, 
                        "isdir": false, 
                        "isfifo": false, 
                        "isgid": false, 
                        "islnk": false, 
                        "isreg": true, 
                        "issock": false, 
                        "isuid": false, 
                        "mode": "0644", 
                        "mtime": 1501710167.0451255, 
                        "nlink": 1, 
                        "path": "/var/logs/qmail/debug.log",
...


I tried many things such as:

      - name: Log matched files
        shell: echo {{ item.path }} /tmp >> /tmp/test.log
        with_subelements:
          - "{{ files_to_delete.results }}"
          - files

but I am not able to get this to work. I've found several blog posts on 
this but either this version of Ansible is broke in regards to this or the 
functionality has changed.

Any ideas?

Thanks!
Michael

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c104dbfc-4079-4a4d-8c32-14aa4689ffb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to