slo*_*ang 4 ansible ansible-tower
当某些主机无法访问时,我正在尝试打印自定义消息。我的问题是,当主机无法访问时,下一个任务将跳过它,因此永远不会触发失败模块。并且可到达的主机也会由于when condition are not met.
我试过了ignore_unreachable: false,还是一样。任何想法将不胜感激。
---
- hosts: prod
gather_facts: no
tasks:
- name: fail when not reachable
action: ping
register: ping_result
# any_errors_fatal: true
- fail:
msg: "please make sure all server up and run again"
when: ping_result.unreachable is defined
any_errors_fatal: true
Run Code Online (Sandbox Code Playgroud)
ignore_unreachable您正在寻找应该设置为 的关键字true,因为您确实希望忽略无法访问的主机以继续执行您的fail任务。
鉴于剧本:
- hosts: nodes
gather_facts: no
tasks:
- ping:
register: ping_result
ignore_unreachable: true
- fail:
msg: "please make sure all server up and run again"
when: ping_result.unreachable is defined
any_errors_fatal: true
Run Code Online (Sandbox Code Playgroud)
这产生:
TASK [ping] *******************************************************
fatal: [node1]: UNREACHABLE! => changed=false
msg: 'Failed to connect to the host via ssh'
skip_reason: Host node1 is unreachable
unreachable: true
fatal: [node2]: UNREACHABLE! => changed=false
msg: 'Failed to connect to the host via ssh'
skip_reason: Host node2 is unreachable
unreachable: true
fatal: [node3]: UNREACHABLE! => changed=false
msg: 'Failed to connect to the host via ssh'
skip_reason: Host node3 is unreachable
unreachable: true
TASK [fail] *******************************************************
fatal: [node1]: FAILED! => changed=false
msg: please make sure all server up and run again
fatal: [node2]: FAILED! => changed=false
msg: please make sure all server up and run again
fatal: [node3]: FAILED! => changed=false
msg: please make sure all server up and run again
NO MORE HOSTS LEFT ************************************************
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5535 次 |
| 最近记录: |