# Permission change based on file extension using ansible

**URL:** <https://forum.ansible.com/t/permission-change-based-on-file-extension-using-ansible/20141>\
**Category:** Ansible Project\
**Created:** [January 7, 2016, 6:59pm UTC](https://forum.ansible.com/t/permission-change-based-on-file-extension-using-ansible/20141 "2016-01-07T18:59:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 7, 2016, 6:59pm UTC](https://forum.ansible.com/t/permission-change-based-on-file-extension-using-ansible/20141/1 "2016-01-07T18:59:53Z")

</div>

I want to change the permission of the file based on it’s extension using ansible, for example I have directory `test` and within this directory I have a lot of shell script(.sh) and python(.py) files. I want to change the permission of shell script to 0700 and python files to 0644. Can you please help me that how I can achieve this. Thanks

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 7, 2016, 7:19pm UTC](https://forum.ansible.com/t/permission-change-based-on-file-extension-using-ansible/20141/2 "2016-01-07T19:19:37Z")

</div>

something like this?:

- find: path=test/  
&nbsp;&nbsp;register: testfiles

- file: path={{item.path}} mode={{ ((item.path|splitext)[0] in ['sh',  
'py'])|ternary('0700','0644') }}  
&nbsp;&nbsp;with\_items: "{{testfiles.files}}"

---

<div class="post-metadata">

**Author:** ![Arbab\_Nazar](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Arbab\_Nazar](https://forum.ansible.com/u/Arbab_Nazar)\
**Post date:** [January 8, 2016, 4:33pm UTC](https://forum.ansible.com/t/permission-change-based-on-file-extension-using-ansible/20141/3 "2016-01-08T16:33:30Z")

</div>

Brain your example change the permission to 0644 to all the files regardless of extension, can you please help me to modified the provided example. Thanks

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 8, 2016, 6:05pm UTC](https://forum.ansible.com/t/permission-change-based-on-file-extension-using-ansible/20141/4 "2016-01-08T18:05:46Z")

</div>

i whipped it up from memory, not tested at all, i see you probably  
need to change the 0 to a 1, but it was meant as a hint not the actual  
solution.
