ansible在playbook中 ignore_error配置案例
在Ansible的playbook中,可以使用ignore_errors参数来配置一个任务出现错误时是否继续执行。以下是一个示例:
- name: Example playbook
hosts: all
tasks:
- name: Task 1
command: /path/to/command
ignore_errors: true
- name: Task 2
command: /path/to/another/command
在上面的示例中,Task 1的ignore_errors参数设置为true,这意味着如果/path/to/command命令执行失败,Ansible将忽略错误并继续执行下一个任务。而Task 2没有配置ignore_errors参数,这意味着如果/path/to/another/command命令执行失败,Ansible将停止执行并报告错误。
此外,还可以在playbook的顶级设置中使用any_errors_fatal参数来配置整个playbook是否在任何错误发生时立即停止执行。以下是一个示例:
- name: Example playbook
hosts: all
any_errors_fatal: true
tasks:
- name: Task 1
command: /path/to/command
- name: Task 2
command: /path/to/another/command
在上面的示例中,any_errors_fatal参数设置为true,这意味着如果Task 1或Task 2中的任何一个命令执行失败,整个playbook都将停止执行并报告错误
原文地址: http://www.cveoy.top/t/topic/h90W 著作权归作者所有。请勿转载和采集!