{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/902","repository_url":"https://api.github.com/repos/ansible/ansible-modules-core","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/902/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/902/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/902/events","html_url":"https://github.com/ansible/ansible-modules-core/issues/902","id":60128986,"number":902,"title":"Add state=empty into file module","user":{"login":"Nindaleth","id":6383928,"avatar_url":"https://avatars.githubusercontent.com/u/6383928?v=3","gravatar_id":"","url":"https://api.github.com/users/Nindaleth","html_url":"https://github.com/Nindaleth","followers_url":"https://api.github.com/users/Nindaleth/followers","following_url":"https://api.github.com/users/Nindaleth/following{/other_user}","gists_url":"https://api.github.com/users/Nindaleth/gists{/gist_id}","starred_url":"https://api.github.com/users/Nindaleth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nindaleth/subscriptions","organizations_url":"https://api.github.com/users/Nindaleth/orgs","repos_url":"https://api.github.com/users/Nindaleth/repos","events_url":"https://api.github.com/users/Nindaleth/events{/privacy}","received_events_url":"https://api.github.com/users/Nindaleth/received_events","type":"User","site_admin":false},"labels":[{"id":439056659,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/affects_1.8","name":"affects_1.8","color":"5319e7","default":false},{"id":132897261,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/feature_idea","name":"feature_idea","color":"006b75","default":false},{"id":414073372,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/waiting_on_maintainer","name":"waiting_on_maintainer","color":"d93f0b","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":84,"created_at":"2015-03-06T17:02:01Z","updated_at":"2016-12-05T19:16:19Z","closed_at":null,"body":"**Issue Type:**\r\n\r\nFeature Idea\r\n\r\n**Ansible Version:**\r\n\r\n```\r\n$ ansible --version\r\nansible 1.8.4\r\n  configured module search path = None\r\n```\r\n\r\n**Environment:**\r\n\r\nN/A\r\n\r\n**Summary:**\r\n\r\nIn our playbooks we need to empty some folders, but currently our only option seems to be using `command` or `shell` module. It has its uses to leave the folder intact as there may have been some owner/permission changes, or alternatively it may be a mountpoint that is not even possible to delete.\r\nSimilar ideas might be had about files as well.\r\n###### Proposed behaviour:\r\n- Directories: remove all files and subdirectories inside so that the directory contains nothing\r\n- Files: truncate the target file, if it was empty then touch it\r\n- Symlinks/Hardlinks: check which of the previous 2 types it is, act accordingly\r\n\r\nState change changed if previously non-empty, ok if previously empty, failed if still non-empty.\r\n###### Example of usage:\r\n\r\n```\r\n- name: Clean folders\r\n  file: path=/var/zookeeper state=empty\r\n\r\n- name: Truncate logs\r\n  file: path=/var/log/local6 state=empty\r\n```\r\n\r\n**Workaround (how to empty a directory completely):**\r\n\r\n```\r\n- find: path=/my/dir file_type=file\r\n  register: files\r\n\r\n- find: path=/my/dir file_type=directory\r\n  register: directories\r\n\r\n- file: state=absent path={{ item.path }}\r\n  with_items: \r\n    - \"{{ files }}\"\r\n    - \"{{ directories }}\"\r\n```\r\n\r\nNot sure if there is a reasonable workaround for emptying _multiple_ directories."},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/comments/264947938","html_url":"https://github.com/ansible/ansible-modules-core/issues/902#issuecomment-264947938","issue_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/902","id":264947938,"user":{"login":"lizhongz","id":3431872,"avatar_url":"https://avatars.githubusercontent.com/u/3431872?v=3","gravatar_id":"","url":"https://api.github.com/users/lizhongz","html_url":"https://github.com/lizhongz","followers_url":"https://api.github.com/users/lizhongz/followers","following_url":"https://api.github.com/users/lizhongz/following{/other_user}","gists_url":"https://api.github.com/users/lizhongz/gists{/gist_id}","starred_url":"https://api.github.com/users/lizhongz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lizhongz/subscriptions","organizations_url":"https://api.github.com/users/lizhongz/orgs","repos_url":"https://api.github.com/users/lizhongz/repos","events_url":"https://api.github.com/users/lizhongz/events{/privacy}","received_events_url":"https://api.github.com/users/lizhongz/received_events","type":"User","site_admin":false},"created_at":"2016-12-05T19:16:19Z","updated_at":"2016-12-05T19:16:19Z","body":"+1"}}
{"actor":{"display_login":"lizhongz"}}