作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个剧本,其中包含三个特定任务。
- name: Execute the compilation script
command: sh {{ working_folder }}/compile.sh
args:
chdir: "{{ working_folder }}"
when: run_deploy_machine == "true"
- name: Execute the deployment script
command: sh {{ working_folder }}/deploy.sh
args:
chdir: "{{ working_folder }}"
when: run_deploy_machine == "true"
- name: Start the JBoss server
shell: . /jboss start
问题是,如果前两个任务中的任何一个失败,我需要(作为失败过程的一部分)激活最后一个任务的逻辑(它可能作为处理程序)。我看到有阻止/救援选项,问题是如果我使用它 - 救援“取消”失败。我只需要在失败的情况下执行启动 JBoss,但 playbook 仍然会失败。
有什么想法可以做到吗?
最佳答案
您仍然可以使用阻止/救援并在救援任务结束时使用失败任务。这是一个全局性的想法:
---
- name: Clean fail in rescue demo
hosts: localhost
gather_facts: false
tasks:
- block:
- name: task that may fail
command: /bin/false
- name: other task that might fail
command: /does/this/work
rescue:
- name: task to remedy fail
command: echo remedy
- name: cleanly fail the host anyway
fail:
msg: clean fail after remedy
关于ansible - 如何在 Ansible 中捕获失败并继续执行特定任务的剧本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63683250/
我是一名优秀的程序员,十分优秀!