使用块时具有ansible playbook角色的语法错误

问题描述 投票:0回答:1

我正在尝试在角色任务文件中使用带有ansible 2.1的块,但是在下面复制时会收到sytax错误:

---
- name: transferring debian artifact to server
  - block:
     - copy:
         src: "{{ lookup('fileglob','{{base_git_path}}testserver/target/*.deb', wantlist=true) | first }}"
         dest: "{{base_destination_path}}"
         owner: xyz
         group: xyz
         mode: 644
         become: true
    rescue:
     - debug: msg="error while locating debian file in tmp directory"

语法错误

fatal: [akka_1]: FAILED! => {"failed": true, "reason": "Syntax Error while loading YAML.\n\n\nThe error appears to have been in '/home/user/test/ansible/testproj/playbooks/roles/tmp3/tasks/synchronize.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n- name: transferring debian artifact to server\n  - block:\n  ^ here\n"}
ansible ansible-playbook ansible-2.x
1个回答
3
投票

block应该与其他任务处于相同的缩进级别。

块也不能有名字。 ⟵更新:自Ansible 2.3以来,这已经改变,块可以有名称。

正确的语法:

---
# transferring debian artifact to server
- block:
    - copy:
        src: ...
  rescue:
    - debug: msg="..."
© www.soinside.com 2019 - 2024. All rights reserved.