Ansible - Mode 755 for directories and 644 for files recursively

后端 未结 4 2015
难免孤独
难免孤独 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:40

    The Ansible file/copy modules don't give you the granularity of specifying permissions based on file type so you'd most likely need to do this manually by doing something along these lines:

    - name: Ensure directories are 0755
      command: find {{ path }} -type d -exec chmod -c 0755 {} \;
      register: chmod_result
      changed_when: "chmod_result.stdout != \"\""
    
    - name: Ensure files are 0644
      command: find {{ path }} -type f -exec chmod -c 0644 {} \;
      register: chmod_result
      changed_when: "chmod_result.stdout != \"\""
    

    These would have the effect of recursing through {{ path }} and changing the permissions of every file or directory to the specified permissions.

提交回复
热议问题