The find module doesn't seem to work with certain file types (block devices)

29 views
Skip to first unread message

Geromy Harper

unread,
Feb 10, 2016, 9:34:10 PM2/10/16
to Ansible Project
Just curious if this is a bug in the find module or if it's working as intended?
Running ansible 2.0.0.2

Demo snippet:
- name: module find mpath
  find: paths='/dev/mapper' patterns='mpath*p*'
  register: modfind_result

- debug: var=modfind_result

- name: shell find mpath
  shell: find /dev/mapper -name mpath*p*
  register: shfind_result

- debug: var=shfind_result


Output:
TASK [module find mpath] *******************************************************
ok: [devwebdb0]

TASK [debug] *******************************************************************
ok: [devwebdb0] => {
    "modfind_result": {
        "changed": false, 
        "examined": 3, 
        "files": [], 
        "matched": 0, 
        "msg": ""
    }
}

TASK [shell find mpath] ********************************************************
changed: [devwebdb0]

TASK [debug] *******************************************************************
ok: [devwebdb0] => {
    "shfind_result": {
        "changed": true, 
        "cmd": "find /dev/mapper -name mpath*p*", 
        "delta": "0:00:00.404326", 
        "end": "2016-02-10 14:51:21.624126", 
        "rc": 0, 
        "start": "2016-02-10 14:51:21.219800", 
        "stderr": "", 
        "stdout": "/dev/mapper/mpath5p1", 
        "stdout_lines": [
            "/dev/mapper/mpath5p1"
        ], 
        "warnings": []
    }
}

modfind_result.examined=3, so it appears to be seeing the device files, however modfind_result.files=[], which would make me think it's not matching the pattern.  Using patterns="*" or leaving it out entirely returns the same results however, and it works just fine if I try and match against a text or binary file.

Brian Coca

unread,
Feb 10, 2016, 10:28:52 PM2/10/16
to ansible...@googlegroups.com
find uses stat.S_ISREG to check if it is a regular file, so  devices, sockets, pipes will all be ignored, we might want to add an option to control the file types.

​-----------
Brian Coca​

Reply all
Reply to author
Forward
0 new messages