-1

I have an ansible task in which I need to verify whether I have all 1987 files and all those files were generated within 1 minute period.

  - name: check all 1987 files
    find: paths=/proc/files
          file_type=file
          age=-{{ window }}m
          age_stamp=mtime
    register: files
    failed_when: files.matched = total | int

But whenever I run above task, it always fails with this error message. I have already checked I have all 1987 files generated properly.

fatal: [machineA]: FAILED! => {"msg": "The conditional check 'files.matched = total | int' failed. The error was: template error while templating string: expected token 'end of statement block', got '='. String: {% if files.matched = total | int %} True {% else %} False {% endif %}"}

Below is how I am passing those arguments:

-e 'total=1987' -e 'window=1'

Here is the error I get: It was showing all 1987 files in json array so I have shortened it down.

{ "changed": false, "examined": 1987, "failed_when_result": true, "files": [{ "atime": 1524849737.1382372, "ctime": 1524849737.4822407, "dev": 64785, "gid": 5000, "inode": 55052752, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1524849737.4822407, "nlink": 1, "path": "/proc/files/abc_1680_log.data", "rgrp": true, "roth": true, "rusr": true, "size": 2687406, "uid": 5000, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false }], "matched": 1987, "msg": "" }
1

This logic seems backwards:

failed_when: files.matched = total | int

It should be

failed_when: files.matched != total | int
1

Comparison is done using two equal-signs:

  - name: check all 1987 files
    find: paths=/proc/files
          file_type=file
          age=-{{ window }}m
          age_stamp=mtime
    register: files
    failed_when: files.matched == total | int

Ansible uses Jinja-templates, you can see the comparisons here: http://jinja.pocoo.org/docs/dev/templates/#comparisons

  • yeah I tried with == but it failed as well. I just need to make sure that I have all 1987 files and they all are generated within 1 minute. Added error in my question. – user5447339 Apr 27 '18 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.