How to check if the current user has write access to a given path ?

I am trying to check via Ansible that whether the user (being used to connect) has write access to a given path - both on linux hosts and windows hosts.

I tried looking around but i could not get an easy way to do that. I might be getting wrong paths a lot, so the typical commands with raw module is not a good idea. So what i thought of is to create try and create a file in the path, possibly with the name as current epoch and later remove it.

Anybody have a better idea on how to do this for windows and linux machines ?

Would stat achieve this for you?

http://docs.ansible.com/ansible/stat_module.html

Directly it didn’t help me. What i did is a 3 step process - create a folder with timestamp in name (for uniqueness), check if it was created and then delete it.