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.

66 lines
2.1 KiB

  1. ---
  2. - name: "Check_certs | check if the certs have already been generated on first master"
  3. find:
  4. paths: "{{ kube_cert_dir }}"
  5. patterns: "*.pem"
  6. get_checksum: true
  7. delegate_to: "{{groups['kube-master'][0]}}"
  8. register: kubecert_master
  9. run_once: true
  10. - name: "Check_certs | Set default value for 'sync_certs', 'gen_certs', and 'secret_changed' to false"
  11. set_fact:
  12. sync_certs: false
  13. gen_certs: false
  14. secret_changed: false
  15. - name: "Check certs | check if a cert already exists on node"
  16. stat:
  17. path: "{{ kube_cert_dir }}/{{ item }}"
  18. register: kubecert_node
  19. with_items:
  20. - ca.pem
  21. - node-{{ inventory_hostname }}-key.pem
  22. - name: "Check_certs | Set 'gen_certs' to true"
  23. set_fact:
  24. gen_certs: true
  25. when: "not item in kubecert_master.files|map(attribute='path') | list"
  26. run_once: true
  27. with_items: >-
  28. ['{{ kube_cert_dir }}/ca.pem',
  29. {% for host in groups['k8s-cluster'] %}
  30. '{{ kube_cert_dir }}/node-{{ host }}-key.pem'
  31. {% if not loop.last %}{{','}}{% endif %}
  32. {% endfor %}]
  33. - name: "Check_certs | Set 'gen_node_certs' to true"
  34. set_fact:
  35. gen_node_certs: |-
  36. {
  37. {% set existing_certs = kubecert_master.files|map(attribute='path')|list|sort %}
  38. {% for host in groups['k8s-cluster'] -%}
  39. {% set host_cert = "%s/node-%s-key.pem"|format(kube_cert_dir, host) %}
  40. {% if host_cert in existing_certs -%}
  41. "{{ host }}": False,
  42. {% else -%}
  43. "{{ host }}": True,
  44. {% endif -%}
  45. {% endfor %}
  46. }
  47. run_once: true
  48. - name: "Check_certs | Set 'sync_certs' to true"
  49. set_fact:
  50. sync_certs: true
  51. when: |-
  52. {%- set certs = {'sync': False} -%}
  53. {% if gen_node_certs[inventory_hostname] or
  54. (not kubecert_node.results[0].stat.exists|default(False)) or
  55. (not kubecert_node.results[1].stat.exists|default(False)) or
  56. (kubecert_node.results[1].stat.checksum|default('') != kubecert_master.files|selectattr("path", "equalto", kubecert_node.results[1].stat.path)|map(attribute="checksum")|first|default('')) -%}
  57. {%- set _ = certs.update({'sync': True}) -%}
  58. {% endif %}
  59. {{ certs.sync }}