Skip to content

Instantly share code, notes, and snippets.

@maxim
Created June 26, 2014 21:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim/0146d15fa18a238f14b9 to your computer and use it in GitHub Desktop.
Save maxim/0146d15fa18a238f14b9 to your computer and use it in GitHub Desktop.
How to recursilvely chmod dirs and files (separately) with Ansible, without always seeing "changed" status.
- name: ensure all dir permissions are set correctly
shell: find /my/dir -type d -print0 | xargs -0 chmod -c 2755
register: chmod_result
changed_when: "chmod_result.stdout != \"\""
- name: ensure all file permissions are set correctly
shell: find /my/dir -type f -print0 | xargs -0 chmod -c 0650
register: chmod_result
changed_when: "chmod_result.stdout != \"\""
@jeffwidman
Copy link

Thanks! Had never seen the -c flag before; looks like it's also supported by GNU chown and chgrp

@ArgonQQ
Copy link

ArgonQQ commented Jun 24, 2017

Amazing! This helped me alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment