Ansible playbook wait until all pods running

前端 未结 2 1525
囚心锁ツ
囚心锁ツ 2021-02-06 12:24

I have this ansible (working) playbook that looks at the output of kubectl get pods -o json until the pod is in the Running state. Now I want to exten

2条回答
  •  逝去的感伤
    2021-02-06 13:05

    I would try something like this (works for me):

    tasks:
    - name: wait for pods to come up
      shell: kubectl get pods -o json
      register: kubectl_get_pods
      until: kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]
    

    You are basically getting all the statuses for all the pods and combining them into a unique list, and then it won't complete until that list is ["Running"]. So for example, if all your pods are not running you will get something like ["Running", "Starting"].

提交回复
热议问题