# Rsync, permissions and idempotence

**URL:** <https://forum.ansible.com/t/rsync-permissions-and-idempotence/40241>\
**Category:** Get Help\
**Created:** [February 13, 2025, 9:27am UTC](https://forum.ansible.com/t/rsync-permissions-and-idempotence/40241 "2025-02-13T09:27:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![microlinux](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/microlinux/32/2968_2.png) [@microlinux](https://forum.ansible.com/u/microlinux)\
**Post date:** [February 13, 2025, 9:27am UTC](https://forum.ansible.com/t/rsync-permissions-and-idempotence/40241/1 "2025-02-13T09:27:15Z")

</div>

Hi,

I’m currently writing a playbook to configure a proxy server using Squid and SquidGuard. There’s a little detail I can’t seem to figure out.

I have an existing `/var/squidGuard` directory where I want to download blacklists from a local university. Here’s what the manual command looks like:

```auto
# cd /var/squidGuard
# rsync -arpogvt rsync://ftp.ut-capitole.fr/blacklist .

```

This results in a new `/var/squidGuard/dest` directory with lots of files.

When I do this manually I set the owner and group of this directory to the `squid` system user and group:

```auto
# chown -R squid:squid dest/

```

Now I wonder how I can make this idempotent.

```auto
    - name: Create download directory
      ansible.builtin.file:
        path: /var/squidGuard/dest
        state: directory
        owner: squid
        group: squid
        mode: 0755

```

Unfortunately when I do this:

```auto
    - name: Fetch blacklists (Université de Toulouse)
      ansible.posix.synchronize:
        src: rsync://ftp.ut-capitole.fr/blacklist
        dest: /var/squidGuard
        delete: true

```

… then I get some weird permissions on my downloaded file tree:

```auto
# ls -l
total 4
drwxr-xr-x. 76 99 99 4096 Feb 12 22:50 dest
# ls -l dest/ | head -n 5
total 192
lrwxrwxrwx. 1 99 99 9 Feb 12 22:50 ads -> publicite
drwxr-xr-x. 2 99 99 100 Feb 12 04:03 adult
lrwxrwxrwx. 1 99 99 8 Feb 12 22:50 aggressive -> agressif
drwxr-xr-x. 2 99 99 65 Feb 11 09:16 agressif

```

I know if I wanted to keep `squid:squid` permissions on my downloaded `dest` files, then the best way to do that would be to execute the `rsync` command as the `squid` system user. Only I don’t know how to translate that into Ansible syntax. I don’t even know if that’s possible.

Any suggestions ?

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [February 13, 2025, 9:50am UTC](https://forum.ansible.com/t/rsync-permissions-and-idempotence/40241/2 "2025-02-13T09:50:53Z")

</div>

Does setting the [owner](https://docs.ansible.com/ansible/latest/collections/ansible/posix/synchronize_module.html#parameter-owner) and [group](https://docs.ansible.com/ansible/latest/collections/ansible/posix/synchronize_module.html#parameter-group) options to `false` with [become\_user](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_privilege_escalation.html#become-directives) set to `squid` solve this?

If that isn’t the answer can you use [rsync\_opts](https://docs.ansible.com/ansible/latest/collections/ansible/posix/synchronize_module.html#parameter-rsync_opts) to solve this issue?

---

<div class="post-metadata">

**Author:** ![microlinux](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/microlinux/32/2968_2.png) [@microlinux](https://forum.ansible.com/u/microlinux)\
**Post date:** [February 13, 2025, 2:18pm UTC](https://forum.ansible.com/t/rsync-permissions-and-idempotence/40241/3 "2025-02-13T14:18:22Z")

</div>

That doesn’t solve the problem. But I think I have a different idea on how to handle this.

Thanks & cheers,

Niki
