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.3 KiB

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