Skip to content

Instantly share code, notes, and snippets.

@maxim
Created June 26, 2014 21:02
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