Ashar
Ashar

Reputation: 3065

Need permissions changed of a folder + files together using Ansible synchronize module

I allow the user the option to enter 3 digit number for setting permission of files or folders being transferred say -e myperm: 775

I use ansible where I provide rsync_opts: --chmod:F775 (synchronize module) to change the permission of the transferred file/folder on the destination to 775

- name: sync file
  synchronize:
    src: /tmp/file.py
    dest: /home/myuser/file.py
    mode: push
    rsync_opts:
      - "--chmod=F0{{ myperm }}"

Above works fine for files; however, the same does not work for transferring folders say when src: /tmp/folder

I tried --chmod=D0{{ myperm }},F0{{ myperm }} in ansible but it translates to --chmod=D0775 F0775 and gives this error:

msg": "Unexpected remote arg: user@desthost:/tmp/folder\nrsync error: syntax or usage error (code 1) at main.c(1344) [sender=3.1.2]\n", "rc": 1}

Can you please suggest rsync_opts with variable myperm for changing permissions of both files and folders?

Any other solution will also be fine.

Upvotes: 1

Views: 1302

Answers (1)

guido
guido

Reputation: 19224

It seems a problem in parsing the comma separated argument when the module generates the rsync command line, however, since rsync allows multiple chmod options, you can rewrite your task as:

[..]
rsync_opts:  
  - "--chmod=F0{{ myperm }}"
  - "--chmod=D0{{ myperm }}"

Upvotes: 1

Related Questions