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