FreeKB - file module (change owner group mode permissions chown chgrp chmod)
Ansible - file module (change owner group mode permissions chown chgrp chmod)

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]

 


Recursive directory

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 5dca7 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |