You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.2 KiB

  1. ---
  2. - hosts: kube-master[0]
  3. tasks:
  4. - name: Force binaries directory for Container Linux by CoreOS
  5. set_fact:
  6. bin_dir: "/opt/bin"
  7. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  8. - set_fact:
  9. bin_dir: "/usr/local/bin"
  10. when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  11. - name: Check kubectl output
  12. shell: "{{bin_dir}}/kubectl get pods --all-namespaces -owide"
  13. register: get_pods
  14. - debug: msg="{{get_pods.stdout}}"
  15. - name: Get pod names
  16. shell: "{{bin_dir}}/kubectl get pods -o json"
  17. register: pods
  18. no_log: true
  19. - name: Get hostnet pods
  20. command: "{{bin_dir}}/kubectl get pods -o
  21. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  22. register: hostnet_pods
  23. - name: Get running pods
  24. command: "{{bin_dir}}/kubectl get pods -o
  25. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  26. register: running_pods
  27. - set_fact:
  28. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  29. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  30. pods_hostnet: |
  31. {% set list = hostnet_pods.stdout.split(" ") %}
  32. {{list}}
  33. pods_running: |
  34. {% set list = running_pods.stdout.split(" ") %}
  35. {{list}}
  36. - name: Check pods IP are in correct network
  37. assert:
  38. that: item | ipaddr(kube_pods_subnet)
  39. when: not item in pods_hostnet and item in pods_running
  40. with_items: "{{pod_ips}}"
  41. - name: Ping between pods is working
  42. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  43. when: not item[0] in pods_hostnet and not item[1] in pods_hostnet
  44. with_nested:
  45. - "{{pod_names}}"
  46. - "{{pod_ips}}"
  47. - name: Ping between hostnet pods is working
  48. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  49. when: item[0] in pods_hostnet and item[1] in pods_hostnet
  50. with_nested:
  51. - "{{pod_names}}"
  52. - "{{pod_ips}}"