Ansible 有没有一种方法可以在没有阻塞/救援的情况下在故障时运行任务?

Ansible 有没有一种方法可以在没有阻塞/救援的情况下在故障时运行任务?,ansible,Ansible,我想在任务失败时运行一些代码(例如任务)。我发现的唯一方法是使用blocks block/rescue方法适用于我的用例,但它在我的剧本中强制使用(否则)不必要的关键字 有没有办法重写以下内容: - name: my play hosts: 127.0.0.0 any_errors_fatal: true connection: local tasks: - name: install something and configure that thing bl

我想在任务失败时运行一些代码(例如任务)。我发现的唯一方法是使用
block
s

block
/
rescue
方法适用于我的用例,但它在我的剧本中强制使用(否则)不必要的关键字

有没有办法重写以下内容:

- name: my play
  hosts: 127.0.0.0
  any_errors_fatal: true
  connection: local
  tasks:
    - name: install something and configure that thing
      block:
        - name: install something
          shell: install something
        - name: configure that something
          shell: do some things
      rescue:
        - name: rollback
          shell: uninstall that thing
我不使用
?通过
救援
(如果可以使用无阻塞救援?)或其他方式。比如:

- name: my play
  hosts: 127.0.0.0
  any_errors_fatal: true
  connection: local
  tasks:
    - name: install something
      shell: install something
    - name: configure that something
      shell: do some things
      rescue:
        - name: rollback
          shell: uninstall that thing

没有办法做到这一点。Rescue不包括block,如果变量为false,您可以在第一个任务中使用
寄存器保存变量,并在
时使用
执行其他任务,但我想最好使用block,而不是这种方式。

没有办法做到这一点。Rescue不包括block,如果变量为false,您可以在第一个任务中使用
register
保存变量,并在
时使用
执行其他任务,但我想最好使用block来代替这种方式。

供您考虑:这不是不必要的,它的作用域是
尝试
的宽度,但
操作除外;如果你只想拯救一项任务,那么按照gary lopez说的做,并使用
忽略错误:yes
注册:
,但是当ansible提供了一种专门的机制时,你真的在向上游游动,实际上,这种机制不需要手动编码
营救:
行为供你考虑:这不是没有必要的,它是为
除了
动作之外的
尝试
的宽度范围;如果你只想拯救一项任务,那么按照gary lopez说的去做,并使用
忽略错误:是的
注册:
,但当ansible提供了一种专门的机制时,你实际上是在上游游弋,而手动编码
拯救:
行为的字符更少