Ansible - Mode 755 for directories and 644 for files recursively

后端 未结 4 1943
难免孤独
难免孤独 2021-01-31 01:15

I\'d like to allow anyone to list and read all files in my directory tree, but I don\'t want to make the files executable :

dir
  \\subdir1
      file1
  \\subdi         


        
4条回答
  •  太阳男子
    2021-01-31 01:58

    This worked for me:

    - file:
        path: dir
        mode: a-x
        recurse: yes
    - file:
        path: dir
        mode: u=rwX,g=rX,o=rX
        recurse: yes
    

    Remove execution permission first from all, otherwise group and others get execution permission to files.

    See chmod man pages about X-directive:

    execute/search only if the file is a directory or already has execute permission for some user (X)

    Also this works:

    - shell: "chmod -R a-x,u=rwX,g=rX,o=rX dir"
    

    For some reason combination of these two does not work:

    - file:
        path: dir
        mode: a-x,u=rwX,g=rX,o=rX
        recurse: yes
    

提交回复
热议问题