当同步属性在Ansible中为多行时,无法默认忽略

当同步属性在Ansible中为多行时,无法默认忽略,ansible,syntax-error,runtime-error,default,rsync,Ansible,Syntax Error,Runtime Error,Default,Rsync,当定义了最终文件\u perm时,下面的Ansible可以正常工作: - name: Copying from "{{ inventory_hostname }}" to this ansible server. synchronize: src: "{{ item }}" dest: "{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/&quo

当定义了
最终文件\u perm
时,下面的Ansible可以正常工作:

   - 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() }}"
但是,我的要求是在新行上有多个多行
rsync\u选项
,如下所示:

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() }}"
   rsync_opts: [ '{{ final_file_perm | default(omit) }}', '{{ final_folder_perm | default(omit) }}' ]
上述操作不起作用,并导致以下错误:

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=<<CHANGED>>%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
但是,我得到了与上面分享的类似的错误

注意:当定义了
final\u file\u perm
final\u folder\u perm
时,这可以正常工作。只有当错误未定义且我希望忽略它们时,才会出现错误


请您提出一个解决方案,我可以对多个换行符上的属性使用
default(omit)

然后您需要有条件地建立
rsync\u opts
列表,而不是在列表中包含相当于
None
项的内容

-name:从“{{inventory\u hostname}}”复制到此ansible服务器。
使同步:
src:“{{item}}”
dest:{{playbook_dir}}/tmpfiles/{{{Latest_Build_Number}}/“
rsync_opts:“{{my_rsync_opts}”
模式:拉
有以下项目:
-“{{source_file.split()}}”
变量:
我的同步选项:>-
{{ [] +
([final_file_perm]如果final_file_perm | d(“”)否则[])+
([final_folder_perm]如果final_folder_perm | d(“”)else[])}