Ansible 不管任务失败都运行处理程序?

Ansible 不管任务失败都运行处理程序?,ansible,ansible-role,ansible-handlers,Ansible,Ansible Role,Ansible Handlers,我有以下几点: 由于模块的性质,我希望clean处理程序始终运行,即使角色中的其他任务失败。根据我的粗略测试,如果运行测试失败,则永远不会调用处理程序,临时文件留在目标机器上 在我的角色中,有没有办法强迫Ansible运行此处理程序,而不管任务中发生了什么?引用本章: 您可以使用-force handlers命令行选项更改此行为,或者在播放中包含force_handlers:True,或者在ansible.cfg中包含force_handlers=True。当强制处理程序时,即使任务在该主机上失

我有以下几点:

由于模块的性质,我希望clean处理程序始终运行,即使角色中的其他任务失败。根据我的粗略测试,如果运行测试失败,则永远不会调用处理程序,临时文件留在目标机器上

在我的角色中,有没有办法强迫Ansible运行此处理程序,而不管任务中发生了什么?

引用本章:

您可以使用-force handlers命令行选项更改此行为,或者在播放中包含force_handlers:True,或者在ansible.cfg中包含force_handlers=True。当强制处理程序时,即使任务在该主机上失败,它们也会在收到通知时运行。请注意,某些错误仍然会阻止处理程序运行,例如主机变得不可访问


没有解释,与处理程序无关,也与损坏的YAML缩进无关…来自审阅队列:我可以请您在您的答案周围添加更多的上下文吗。只有代码的答案很难理解。如果你能在你的文章中添加更多的信息,这将有助于询问者和未来的读者。另请参见。如果您包括一个示例,这将更加有用。。。
---
 # optionally find the latest version of goss using the GitHub "API"
 - name: detect latest version
   shell: |
    curl -sIS https://github.com/aelsabbahy/goss/releases/latest | \
      tr -d '\r' | \
      grep -oP '(?<=Location:\s).*' | \
      grep -oP '(?<=v)\d+\.\d+\.\d+'
   register: detected_latest
   when: version == "latest"

 - name: set detected version
   set_fact:
     real_version: "{{ detected_latest.stdout.strip() }}"
   when: version == "latest"

 - name: set specified verison
   set_fact:
     real_version: "{{ version }}"
   when: version != "latest"

 # set play facts
 - name: set facts
   set_fact:
     download_url: "https://github.com/aelsabbahy/goss/releases/download/v{{ real_version }}/goss-linux-amd64"

 # create goss directories
 - name: create goss directories
   file: path={{ item }} state=directory
   with_items:
     - /tmp/degoss
     - /tmp/degoss/bin
     - /tmp/degoss/tests
   notify: clean

 # download goss
 - name: install
   get_url:
     url: "{{ download_url }}"
     dest: /tmp/degoss/bin/goss
     mode: 0755

 # deploy test cases
 - name: deploy tests
   copy: src={{ item }} dest=/tmp/degoss/tests/
   with_items: "{{ tests }}"

 # run the tests
 - name: run tests
   goss: executable=/tmp/degoss/bin/goss path="{{ item }}" format="{{ format }}"
   with_fileglob: /tmp/degoss/tests/*.yml
---
# handlers file for degoss
 - name: clean
   file: path=/tmp/degoss state=absent
    ---
    # tasks file for block
    - name: command 0
      shell: uname -i

    - block:
      - name: command1
        shell: ls /tmp/
      - name: command2
        shell: ls /tmp/momo

  rescue:
  - name: retour arriere ya eu une erreur
    shell: ls -ls