Looping for find results

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