{"action":"closed","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/14453","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/14453/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/14453/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/14453/events","html_url":"https://github.com/ansible/ansible/issues/14453","id":133249686,"number":14453,"title":"\"find\" module doesn't recognize symlinks correctly","user":{"login":"Yannik","id":801996,"avatar_url":"https://avatars.githubusercontent.com/u/801996?v=3","gravatar_id":"","url":"https://api.github.com/users/Yannik","html_url":"https://github.com/Yannik","followers_url":"https://api.github.com/users/Yannik/followers","following_url":"https://api.github.com/users/Yannik/following{/other_user}","gists_url":"https://api.github.com/users/Yannik/gists{/gist_id}","starred_url":"https://api.github.com/users/Yannik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yannik/subscriptions","organizations_url":"https://api.github.com/users/Yannik/orgs","repos_url":"https://api.github.com/users/Yannik/repos","events_url":"https://api.github.com/users/Yannik/events{/privacy}","received_events_url":"https://api.github.com/users/Yannik/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-12T14:02:43Z","updated_at":"2016-02-12T15:03:35Z","closed_at":"2016-02-12T15:03:35Z","body":"##### Issue Type: Bug Report\r\n\r\n##### Ansible Version: 2.0.2\r\n\r\n##### Ansible Configuration: default configuration\r\n\r\n##### Environment: debian jessie\r\n\r\n##### Summary:\r\n\r\nWhen using the \"find\" module, symlinks are falsely identified as regular files.\r\n\r\n##### Steps To Reproduce:\r\n\r\n\r\nHow to reproduce:\r\n```\r\nmkdir /tmp/test\r\ntouch /tmp/file\r\nln -s /tmp/file /tmp/test/symlink\r\n```\r\n\r\nthen run a playbook like this:\r\n```\r\n---\r\n- hosts: localhost\r\n  tasks:\r\n  - find: paths=\"/tmp/test\"\r\n    register: find_result\r\n  - debug: var=find_result\r\n```\r\n\r\n##### Expected Results:\r\n\r\n```\r\n        \"files\": [ \r\n            { \r\n                \"islnk\": true,  \r\n                \"isreg\": false,  \r\n                \"path\": \"/tmp/test/symlink\",  \r\n            }\r\n         ]\r\n```\r\n\r\n##### Actual Results:\r\n\r\nIn the output, you will see\r\n```\r\n        \"files\": [ \r\n            { \r\n                \"islnk\": false,  \r\n                \"isreg\": true,  \r\n                \"path\": \"/tmp/test/symlink\",  \r\n            }\r\n         ]\r\n```\r\n\r\nWhen running\r\n ```  - find: paths=\"/tmp/test\" file_type=file```\r\nto explicitly only match regular files, the result is the same (the symlink is in the results array).\r\n\r\n##### Solution\r\n\r\nThe reason for this is that [os.stat](https://docs.python.org/2/library/os.html#os.stat) is used to get the file info: https://github.com/ansible/ansible-modules-core/blob/devel/files/find.py#L316, and ```os.stat``` follows symlinks.\r\nInstead, [os.lstat](https://docs.python.org/2/library/os.html#os.lstat) should be used, which does not follow symlinks.\r\nIt would also be possible to add an additional option ```follow_symlinks=yes/no``` to determine behaviour for this, but IMO, not following symlinks should be the default. \r\n"}}