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.

58 lines
1.9 KiB

  1. ---
  2. - hosts: node1
  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: Get pod names
  12. shell: "{{bin_dir}}/kubectl get pods -o json"
  13. register: pods
  14. no_log: true
  15. - name: Get hostnet pods
  16. command: "{{bin_dir}}/kubectl get pods -o
  17. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {end}'"
  18. register: hostnet_pods
  19. - name: Get running pods
  20. command: "{{bin_dir}}/kubectl get pods -o
  21. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {end}'"
  22. register: running_pods
  23. - set_fact:
  24. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  25. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  26. pods_hostnet: |
  27. {% set list = hostnet_pods.stdout.split(" ") %}
  28. {{list}}
  29. pods_running: |
  30. {% set list = running_pods.stdout.split(" ") %}
  31. {{list}}
  32. - name: Check pods IP are in correct network
  33. assert:
  34. that: item | ipaddr(kube_pods_subnet)
  35. when: not item in pods_hostnet and item in pods_running
  36. with_items: "{{pod_ips}}"
  37. - name: Ping between pods is working
  38. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  39. when: not item[0] in pods_hostnet and not item[1] in pods_hostnet
  40. with_nested:
  41. - "{{pod_names}}"
  42. - "{{pod_ips}}"
  43. - name: Ping between hostnet pods is working
  44. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  45. when: item[0] in pods_hostnet and item[1] in pods_hostnet
  46. with_nested:
  47. - "{{pod_names}}"
  48. - "{{pod_ips}}"