{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3095","repository_url":"https://api.github.com/repos/ansible/ansible-modules-core","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3095/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3095/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3095/events","html_url":"https://github.com/ansible/ansible-modules-core/pull/3095","id":135482402,"number":3095,"title":"Add state=empty into file module (Fixes #902)","user":{"login":"robputt796","id":6697027,"avatar_url":"https://avatars.githubusercontent.com/u/6697027?v=3","gravatar_id":"","url":"https://api.github.com/users/robputt796","html_url":"https://github.com/robputt796","followers_url":"https://api.github.com/users/robputt796/followers","following_url":"https://api.github.com/users/robputt796/following{/other_user}","gists_url":"https://api.github.com/users/robputt796/gists{/gist_id}","starred_url":"https://api.github.com/users/robputt796/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robputt796/subscriptions","organizations_url":"https://api.github.com/users/robputt796/orgs","repos_url":"https://api.github.com/users/robputt796/repos","events_url":"https://api.github.com/users/robputt796/events{/privacy}","received_events_url":"https://api.github.com/users/robputt796/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/feature_pull_request","name":"feature_pull_request","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-22T17:20:39Z","updated_at":"2016-02-22T21:24:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/3095","html_url":"https://github.com/ansible/ansible-modules-core/pull/3095","diff_url":"https://github.com/ansible/ansible-modules-core/pull/3095.diff","patch_url":"https://github.com/ansible/ansible-modules-core/pull/3095.patch"},"body":"**Note to reviewer - I could see no unit tests included in ansible-modules-core so I have assumed tests are not required, however please let me know if a test or docs commit is also required.**\r\n\r\n##### Issue Type:\r\n\r\nPlease pick one and delete the rest:\r\n - Feature Pull Request (Fixes #902)\r\n\r\n##### Plugin Name:\r\nFile\r\n\r\n##### Ansible Version:\r\nansible 1.9.4\r\n\r\n##### Summary:\r\n(Fixes #902)\r\n\r\nAdds the ability to perform the following\r\n\r\nfile: path=/tmp/myfolder state=empty\r\nor\r\nfile: path=/tmp/myfile state=empty\r\n\r\nIn the case of a file this truncates the file to 0 bytes leaving an empty file, in the case of a folder it removes recursively all contents of the folder leaving an empty folder without editing any other elements such as ownership or permissions. If it is ran against a file or directory which does not exist it does not create the file or directory, this should be done via an ensure prior to making sure the state is empty.\r\n\r\n##### Example output:\r\nansible-playbook -vvvv -i '104.130.30.247,' ~/test.yaml --user=root\r\n ____________\r\n< PLAY [all] >\r\n ------------\r\n        \\   ^__^\r\n         \\  (oo)\\_______\r\n            (__)\\       )\\/\\\r\n                ||----w |\r\n                ||     ||\r\n\r\n\r\n _________________\r\n< GATHERING FACTS >\r\n -----------------\r\n        \\   ^__^\r\n         \\  (oo)\\_______\r\n            (__)\\       )\\/\\\r\n                ||----w |\r\n                ||     ||\r\n\r\n\r\n<104.130.30.247> ESTABLISH CONNECTION FOR USER: root\r\n<104.130.30.247> REMOTE_MODULE setup\r\n<104.130.30.247> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=\"/home/robe8437/.ansible/cp/ansible-ssh-%h-%p-%r\" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 104.130.30.247 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1456161437.45-166695396617657 && echo $HOME/.ansible/tmp/ansible-tmp-1456161437.45-166695396617657'\r\n<104.130.30.247> PUT /tmp/tmpMR9AA6 TO /root/.ansible/tmp/ansible-tmp-1456161437.45-166695396617657/setup\r\n<104.130.30.247> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=\"/home/robe8437/.ansible/cp/ansible-ssh-%h-%p-%r\" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 104.130.30.247 /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1456161437.45-166695396617657/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1456161437.45-166695396617657/ >/dev/null 2>&1'\r\nok: [104.130.30.247]\r\n __________________\r\n< TASK: empty file >\r\n ------------------\r\n        \\   ^__^\r\n         \\  (oo)\\_______\r\n            (__)\\       )\\/\\\r\n                ||----w |\r\n                ||     ||\r\n\r\n\r\n<104.130.30.247> ESTABLISH CONNECTION FOR USER: root\r\n<104.130.30.247> REMOTE_MODULE file path=/tmp/file state=empty\r\n<104.130.30.247> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=\"/home/robe8437/.ansible/cp/ansible-ssh-%h-%p-%r\" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 104.130.30.247 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1456161439.8-132728730069085 && echo $HOME/.ansible/tmp/ansible-tmp-1456161439.8-132728730069085'\r\n<104.130.30.247> PUT /tmp/tmp19i2YN TO /root/.ansible/tmp/ansible-tmp-1456161439.8-132728730069085/file\r\n<104.130.30.247> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=\"/home/robe8437/.ansible/cp/ansible-ssh-%h-%p-%r\" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 104.130.30.247 /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1456161439.8-132728730069085/file; rm -rf /root/.ansible/tmp/ansible-tmp-1456161439.8-132728730069085/ >/dev/null 2>&1'\r\nchanged: [104.130.30.247] => {\"changed\": true, \"dest\": \"/tmp/file\", \"diff\": {\"after\": {\"path\": \"/tmp/file\", \"state\": \"empty\"}, \"before\": {\"path\": \"/tmp/file\", \"state\": \"file\"}}, \"gid\": 0, \"group\": \"root\", \"mode\": \"0644\", \"owner\": \"root\", \"size\": 0, \"state\": \"file\", \"uid\": 0}\r\n _________________\r\n< TASK: empty dir >\r\n -----------------\r\n        \\   ^__^\r\n         \\  (oo)\\_______\r\n            (__)\\       )\\/\\\r\n                ||----w |\r\n                ||     ||\r\n\r\n\r\n<104.130.30.247> ESTABLISH CONNECTION FOR USER: root\r\n<104.130.30.247> REMOTE_MODULE file path=/tmp/folder state=empty\r\n<104.130.30.247> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=\"/home/robe8437/.ansible/cp/ansible-ssh-%h-%p-%r\" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 104.130.30.247 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1456161441.87-249090456980746 && echo $HOME/.ansible/tmp/ansible-tmp-1456161441.87-249090456980746'\r\n<104.130.30.247> PUT /tmp/tmpgLlafp TO /root/.ansible/tmp/ansible-tmp-1456161441.87-249090456980746/file\r\n<104.130.30.247> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=\"/home/robe8437/.ansible/cp/ansible-ssh-%h-%p-%r\" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 104.130.30.247 /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1456161441.87-249090456980746/file; rm -rf /root/.ansible/tmp/ansible-tmp-1456161441.87-249090456980746/ >/dev/null 2>&1'\r\nchanged: [104.130.30.247] => {\"changed\": true, \"dest\": \"/tmp/folder\", \"diff\": {\"after\": {\"path\": \"/tmp/folder\", \"state\": \"empty\"}, \"before\": {\"path\": \"/tmp/folder\", \"state\": \"directory\"}}, \"gid\": 0, \"group\": \"root\", \"mode\": \"0755\", \"owner\": \"root\", \"size\": 4096, \"state\": \"directory\", \"uid\": 0}\r\n ____________\r\n< PLAY RECAP >\r\n ------------\r\n        \\   ^__^\r\n         \\  (oo)\\_______\r\n            (__)\\       )\\/\\\r\n                ||----w |\r\n                ||     ||\r\n\r\n\r\n104.130.30.247             : ok=3    changed=2    unreachable=0    failed=0 \r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/comments/187389196","html_url":"https://github.com/ansible/ansible-modules-core/pull/3095#issuecomment-187389196","issue_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3095","id":187389196,"user":{"login":"j-carpentier","id":6650410,"avatar_url":"https://avatars.githubusercontent.com/u/6650410?v=3","gravatar_id":"","url":"https://api.github.com/users/j-carpentier","html_url":"https://github.com/j-carpentier","followers_url":"https://api.github.com/users/j-carpentier/followers","following_url":"https://api.github.com/users/j-carpentier/following{/other_user}","gists_url":"https://api.github.com/users/j-carpentier/gists{/gist_id}","starred_url":"https://api.github.com/users/j-carpentier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j-carpentier/subscriptions","organizations_url":"https://api.github.com/users/j-carpentier/orgs","repos_url":"https://api.github.com/users/j-carpentier/repos","events_url":"https://api.github.com/users/j-carpentier/events{/privacy}","received_events_url":"https://api.github.com/users/j-carpentier/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T21:24:33Z","updated_at":"2016-02-22T21:24:33Z","body":"Really nice to see this option added to file modules !"}}