我有一个Ansible任务几乎与上面的答案相同:Ansible playbook wait until all pods running
- name: Wait for all control-plane pods become created
shell: "kubectl get po --namespace=kube-system --selector tier=control-plane --output=jsonpath='{.items[*].metadata.name}'"
register: control_plane_pods_created
until: item in control_plane_pods_created.stdout
retries: 10
delay: 30
with_items:
- etcd
- kube-apiserver
- kube-controller-manager
- kube-scheduler
- name: Wait for control-plane pods become ready
shell: "kubectl wait --namespace=kube-system --for=condition=Ready pods --selector tier=control-plane --timeout=600s"
register: control_plane_pods_ready
- debug: var=control_plane_pods_ready.stdout_lines
如他的示例所示,它将“FAILED”打印3次:
TASK [Wait for all control-plane pods become created]******************************
FAILED - RETRYING: Wait all control-plane pods become created (10 retries left).
FAILED - RETRYING: Wait all control-plane pods become created (9 retries left).
FAILED - RETRYING: Wait all control-plane pods become created (8 retries left).
changed: [localhost -> localhost] => (item=etcd)
changed: [localhost -> localhost] => (item=kube-apiserver)
changed: [localhost -> localhost] => (item=kube-controller-manager)
changed: [localhost -> localhost] => (item=kube-scheduler)
TASK [Wait for control-plane pods become ready]********************************
changed: [localhost -> localhost]
TASK [debug]*******************************************************************
ok: [localhost] => {
"control_plane_pods_ready.stdout_lines": [
"pod/etcd-localhost.localdomain condition met",
"pod/kube-apiserver-localhost.localdomain condition met",
"pod/kube-controller-manager-localhost.localdomain condition met",
"pod/kube-scheduler-localhost.localdomain condition met"
]
}
对于我的实现,循环失败超过3次,更像是20次...所以它阻塞了我的日志...但这是预期的行为。
那么,如何才能在所有重试次数用完后才打印“失败”?
我希望我的问题是有意义的,谢谢
1条答案
按热度按时间n6lpvg4x1#
我知道您正在引用
until
retries
,并希望重试任务,直到满足条件,并且消息FAILED
属于循环,而不是最终任务结果。运行短时故障测试
产生输出
无论是使用定义故障还是使用
no_log
或限制循环输出保护敏感数据,似乎都无法在剧本级别上抑制Ansible的until
retries
循环的临时消息。对,除非你没有解决Callback plugins和设置一个(其他)回调插件的ansible-playbook或开发(自己的)回调插件的消息将保持。
类似问答
until
retries
loop?更多信息
ansible/plugins/callback/default.py
可能的解决方案
diy
callback – Customize the output