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.

84 lines
3.0 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. '{{ etcd_cert_dir }}/admin-{{ host }}-key.pem',
  35. '{{ etcd_cert_dir }}/member-{{ host }}-key.pem'
  36. {% if not loop.last %}{{','}}{% endif %}
  37. {% endfor %}]
  38. - name: "Check_certs | Set 'gen_master_certs' to true"
  39. set_fact:
  40. gen_master_certs: |-
  41. {
  42. {% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort -%}
  43. {% set existing_certs = etcdcert_master.files|map(attribute='path')|list|sort %}
  44. {% for host in all_etcd_hosts -%}
  45. {% set host_cert = "%s/member-%s-key.pem"|format(etcd_cert_dir, host) %}
  46. {% if host_cert in existing_certs -%}
  47. "{{ host }}": False,
  48. {% else -%}
  49. "{{ host }}": True,
  50. {% endif -%}
  51. {% endfor %}
  52. }
  53. run_once: true
  54. - name: "Check_certs | Set 'gen_node_certs' to true"
  55. set_fact:
  56. gen_node_certs: |-
  57. {
  58. {% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort -%}
  59. {% set existing_certs = etcdcert_master.files|map(attribute='path')|list|sort %}
  60. {% for host in all_etcd_hosts -%}
  61. {% set host_cert = "%s/node-%s-key.pem"|format(etcd_cert_dir, host) %}
  62. {% if host_cert in existing_certs -%}
  63. "{{ host }}": False,
  64. {% else -%}
  65. "{{ host }}": True,
  66. {% endif -%}
  67. {% endfor %}
  68. }
  69. run_once: true
  70. - name: "Check_certs | Set 'sync_certs' to true"
  71. set_fact:
  72. sync_certs: true
  73. when:
  74. - gen_node_certs[inventory_hostname] or
  75. gen_master_certs[inventory_hostname] or
  76. (not etcdcert_node.results[0].stat.exists|default(false)) or
  77. (not etcdcert_node.results[1].stat.exists|default(false)) or
  78. (etcdcert_node.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcdcert_node.results[1].stat.path)|map(attribute="checksum")|first|default(''))