# shell module find -exec chown - how to parse/escape {} \\; ?

**URL:** <https://forum.ansible.com/t/shell-module-find-exec-chown-how-to-parse-escape/21936>\
**Category:** Ansible Project\
**Created:** [July 6, 2016, 4:49pm UTC](https://forum.ansible.com/t/shell-module-find-exec-chown-how-to-parse-escape/21936 "2016-07-06T16:49:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [July 6, 2016, 4:49pm UTC](https://forum.ansible.com/t/shell-module-find-exec-chown-how-to-parse-escape/21936/1 "2016-07-06T16:49:18Z")

</div>

I want to find and chown about 4000 users’ files while migrating to a new authentication protocol and domain.

I have a task that looks like this:  
`

- name: find and fix UID ownerships in all staff homedirs  
shell: “find {{‘~’+item.name | expanduser }} -uid {{item.uid}} -exec chown {{item.name}} {} ;”  
with\_items:
- “{{staff|default()}}”
- “{{students|default()}}”
- “{{staffstuaccounts|default()}}”  
when: item.uid is defined

`

And I get this syntax error:

`

- name: find and fix UID ownerships in all staff homedirs  
shell: “find {{‘~’+item.name | expanduser }} -uid {{item.uid}} -exec chown {{item.name}} {} ;”  
^ here  
We could be wrong, but this one looks like it might be an issue with  
missing quotes. Always quote template expression brackets when they  
start a value.  
`

I would use built-in modules, but find doesn’t find owners. Stat (as far as I can tell) doesn’t go recursive. I’m a little nervous about registering output from find and then writing a new file task to chown the results (which would have to use with\_together, I think), in case the user list order gets out of sync between two tasks. Is there a way to escape this shell expression so it will work?

Thanks!  
Joanna

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [July 6, 2016, 6:25pm UTC](https://forum.ansible.com/t/shell-module-find-exec-chown-how-to-parse-escape/21936/2 "2016-07-06T18:25:55Z")

</div>

I figured it out. I also switched to batch mode instead of single mode:

`shell: "find /home/staff -gid {{item.0.stdout}} -exec chgrp {{item.1.stdout}} \\{\\} +"`
