Permission change based on file extension using ansible

71 views
Skip to first unread message

Arbab Nazar

unread,
Jan 7, 2016, 1:59:54 PM1/7/16
to Ansible Project
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

Brian Coca

unread,
Jan 7, 2016, 2:19:49 PM1/7/16
to Ansible Project
something like this?:

- find: path=test/
register: testfiles

- file: path={{item.path}} mode={{ ((item.path|splitext)[0] in ['sh',
'py'])|ternary('0700','0644') }}
with_items: "{{testfiles.files}}"
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/07141eef-de81-4633-89c3-5579baee927b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Arbab Nazar

unread,
Jan 8, 2016, 11:33:38 AM1/8/16
to ansible...@googlegroups.com
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


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/cM4ls48Mt8Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Brian Coca

unread,
Jan 8, 2016, 1:05:53 PM1/8/16
to Ansible Project
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.
> https://groups.google.com/d/msgid/ansible-project/CAMfRAgnVmOMz6Yq5vd7_czy%3DQJLspAQVXUML%3DO5Z0J4-TDmJ-w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages