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

Unable to default omit when synchronize attributes are multiline in Ansible

Below Ansible works fine when final_file_perm is defined:

  • name: Copying from “{{ inventory_hostname }}” to this ansible server.
    synchronize:
    src: “{{ item }}”
    dest: “{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/”
    rsync_opts: “{{ final_file_perm | default(omit) }}”
    mode: pull
    with_items: - “{{ source_file.split() }}”

However, my requirement is to have multiple multiline rsync_opts on new line like below:

rsync_opts:

  • “–chmod=F0775”

  • “–chmod=D0775”

  • name: Copying from “{{ inventory_hostname }}” to this ansible server.
    synchronize:
    src: “{{ item }}”
    dest: “{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/”
    rsync_opts:

  • “{{ final_file_perm | default(omit) }}”

  • “{{ final_folder_perm | default(omit) }}”
    mode: pull
    with_items: - “{{ source_file.split() }}”

The above does not work and give me the following error:

TASK [Copying from “remhost” to this ansible server.] ********************* failed: [remhost] (item=/u/files/inst.zip) => {“changed”: false, “cmd”: “/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/share/centrifydc/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null __omit_place_holder__6fd53eb1f5a7fbe7c6691ba6f3aada2e52378343 __omit_place_holder__6fd53eb1f5a7fbe7c6691ba6f3aada2e52378343 --out-format=<>%i %n%L remuser@remhost:/u/files/inst.zip /web/playbooks/filecopy/tmpfiles/124/”, “item”: “/u/files/inst.zip”, “msg”: “Unexpected remote arg: remuser@remhost:/u/files/inst.zip\nrsync error: syntax or usage error (code 1) at main.c(1344) [sender=3.1.2]\n”, “rc”: 1} to retry, use: --limit @/web/playbooks/filecopy/copyfiles.retry

I also tried the following:

rsync_opts: [ ‘{{ final_file_perm | default(omit) }}’, ‘{{ final_folder_perm | default(omit) }}’ ]

But, i get the same error.

Note: this works fine when final_file_perm and final_folder_perm are defined. Errors only when they are undefined and I wish to omit them.

Can you please propose a solution where I can use default(omit) for attributes on multi newlines?