The "file" module can be used to change the owner, group, and/or mode of a file. 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.
--- - hosts: all tasks: - name: recursively update /tmp directory owner file: path: /tmp state: directory recurse: yes owner: root