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. - 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: >-
  28. ['{{etcd_cert_dir}}/ca.pem',
  29. {% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort %}
  30. {% for host in all_etcd_hosts %}
  31. '{{etcd_cert_dir}}/node-{{ host }}-key.pem'
  32. {% if not loop.last %}{{','}}{% endif %}
  33. {% endfor %}]
  34. - name: "Check_certs | Set 'gen_node_certs' to true"
  35. set_fact:
  36. gen_node_certs: |-
  37. {
  38. {% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort -%}
  39. {% set existing_certs = etcdcert_master.files|map(attribute='path')|list|sort %}
  40. {% for host in all_etcd_hosts -%}
  41. {% set host_cert = "%s/node-%s-key.pem"|format(etcd_cert_dir, host) %}
  42. {% if host_cert in existing_certs -%}
  43. "{{ host }}": False,
  44. {% else -%}
  45. "{{ host }}": True,
  46. {% endif -%}
  47. {% endfor %}
  48. }
  49. run_once: true
  50. - name: "Check_certs | Set 'sync_certs' to true"
  51. set_fact:
  52. sync_certs: true
  53. when:
  54. - gen_node_certs[inventory_hostname] or
  55. (not etcdcert_node.results[0].stat.exists|default(false)) or
  56. (not etcdcert_node.results[1].stat.exists|default(false)) or
  57. (etcdcert_node.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcdcert_node.results[1].stat.path)|map(attribute="checksum")|first|default(''))