The file module can be used to change the owner, group, and/or mode of a file on a managed node (e.g. target system). Or, the local_action module can be used to invoke this module on the control node (that's your Ansible server).
The ansible-doc file command can be used to show the Ansible documention on the file module.
In this example, the owner/group/mode of /tmp/foo.txt will be updated.
- name: "update foo.txt owner group mode" file: path: /tmp/foo.txt owner: "root" group: "root" mode: "0664"
The task should ok if the owner/group/mode were not updated.
TASK [update foo.txt owner group mode] ok: [server1.example.com]
The task should have changed if the owner/group/mode were updated.
TASK [update foo.txt owner group mode] changed: [server1.example.com]
The state: directory and recurse: yes options can be used to update the owner of every file and directory below a certain directory. In this example, every file and directory below the /tmp directory will be updated to be owned by root.
- name: "recursively update /tmp directory owner" file: path: "/tmp" state: "directory" recurse: "yes" owner: "root"
Or like this, to give "group" the "write" permission.
- name: "recursively update /tmp directory" file: path: "/tmp" state: "directory" recurse: "yes" mode: "g+w"
Refer to the following articles for more details on the owner, group, and mode parameters.