Search code examples
ansiblepermissions

Ansible - Changing permission for all folders in path


In our playbooks we have multiple different paths which needs to have the same permissions.

I'm looking for a way how to change permissions for every folder in path so i.e. for /opt/this/is/just/an/example I need to change permissions for 5 folders (this, is, just, an, example). Only opt will be not changed.

The problem is that the paths can have different lenghts so there might be /opt/something/else in the future. These folders can contain other folders, not specified in our playbooks or files for which we cannot change permissions.

Do you know how can I do this?


Solution

  • According the documentation file module – Manage files and file properties you may try

    - name: Change permissions for '/opt/this'
      file:
        dest: "/opt/this/"
        owner: 'user'
        group: 'group'
        recurse: true 
        # supposed to set directories to 755 and files to 644
        mode: u=rwX,g=rX,o=rX
    

    Thanks to