Ansible块继续因语法错误而失败

时间:2020-04-07 15:09:00

标签: ansible

我尝试从s3下载,当我失败时,我想做其他任务
我阅读了可以使用的文档:阻止/救援
https://docs.ansible.com/ansible/2.7/user_guide/playbooks_blocks.html

因此我正在做的这作为独立任务很好运行

---

    - name: s3 Handler
      gather_facts: false
      hosts: localhost
      connection: local
      tasks:

        - name: Handle the error
          block:
             - name: Get S3 key   
                module: aws_s3
                bucket: dist
                object: packages/foo.zip11
                dest: /home/foo.zip
                mode: get
                overwrite: different


          rescue:
             - debug:
                 msg: 'I caught an error, can do stuff here to fix it, :-)'


但是这里我收到语法错误:

The error appears to have been in '/home/create_s3.yml': line 12, column 19, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

         - name: Get S3 key
            module: aws_s3
                  ^ here

1 个答案:

答案 0 :(得分:0)

看着S3 module from Ansible,看来您可以将module: aws_s3替换为aws_s3

此外,您希望对齐缩进,以使aws_s3name处于同一级别,因为它们在相同的词法范围内。 YAML倾向于对缩进非常挑剔。

将此代码应用于您的代码段,我们得到...

---

    - name: s3 Handler
      gather_facts: false
      hosts: localhost
      connection: local
      tasks:

        - name: Handle the error
          block:
             - name: Get S3 key   
               aws_s3:
                 bucket: dist
                 object: packages/foo.zip11
                 dest: /home/foo.zip
                 mode: get
                 overwrite: different


          rescue:
             - debug:
                 msg: 'I caught an error, can do stuff here to fix it, :-)'