Ill*_*ist 41 ansible ansible-playbook
我正在学习Ansible.我有一个清理资源的剧本,我希望剧本忽略每一个错误并一直持续到最后,如果有错误则最后失败.
我可以忽略错误
ignore_errors: yes
Run Code Online (Sandbox Code Playgroud)
如果这是一项任务,我可以做一些事情(来自ansible错误捕获)
- name: this command prints FAILED when it fails
command: /usr/bin/example-command -x -y -z
register: command_result
ignore_errors: True
- name: fail the play if the previous command did not succeed
fail: msg="the command failed"
when: "'FAILED' in command_result.stderr"
Run Code Online (Sandbox Code Playgroud)
我怎么会在最后失败?我有几个任务,我的"何时"条件是什么?
cle*_*ssi 28
使用失败模块.
Run Code Online (Sandbox Code Playgroud)- fail: msg="The execution has failed because of errors." when: flag == "failed"
更新:
使用register存储您在示例中显示的任务结果.然后,使用这样的任务:
- name: Set flag
set_fact: flag = failed
when: "'FAILED' in command_result.stderr"
Run Code Online (Sandbox Code Playgroud)
Olg*_*ga 17
您可以将所有可能在块中失败的任务包装起来,并ignore_errors: yes与该块一起使用.
tasks:
- name: ls
command: ls -la
- name: pwd
command: pwd
- block:
- name: ls non-existing txt file
command: ls -la no_file.txt
- name: ls non-existing pic
command: ls -la no_pic.jpg
ignore_errors: yes
Run Code Online (Sandbox Code Playgroud)
了解更多关于错误处理块这里.
| 归档时间: |
|
| 查看次数: |
84137 次 |
| 最近记录: |