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.

53 lines
1.8 KiB

  1. ---
  2. - name: "Check_certs | check if all certs have already been generated on first master"
  3. stat:
  4. path: "{{ etcd_cert_dir }}/{{ item }}"
  5. get_md5: no
  6. delegate_to: "{{groups['etcd'][0]}}"
  7. register: etcdcert_master
  8. run_once: true
  9. with_items: >-
  10. ['ca.pem',
  11. {% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique %}
  12. {% for host in all_etcd_hosts %}
  13. 'node-{{ host }}-key.pem'
  14. {% if not loop.last %}{{','}}{% endif %}
  15. {% endfor %}]
  16. - name: "Check_certs | Set default value for 'sync_certs', 'gen_certs' and 'etcd_secret_changed' to false"
  17. set_fact:
  18. sync_certs: false
  19. gen_certs: false
  20. etcd_secret_changed: false
  21. - name: "Check_certs | Set 'gen_certs' to true"
  22. set_fact:
  23. gen_certs: true
  24. when: "not {{item.stat.exists}}"
  25. run_once: true
  26. with_items: "{{etcdcert_master.results}}"
  27. - name: "Check certs | check if a cert already exists"
  28. stat:
  29. path: "{{ etcd_cert_dir }}/{{ item }}"
  30. register: etcdcert
  31. with_items:
  32. - ca.pem
  33. - node-{{ inventory_hostname }}-key.pem
  34. - name: "Check_certs | Set 'sync_certs' to true"
  35. set_fact:
  36. sync_certs: true
  37. when: >-
  38. {%- set certs = {'sync': False} -%}
  39. {% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique %}
  40. {% for host in all_etcd_hosts %}
  41. {% if host == inventory_hostname %}
  42. {% if (not etcdcert.results[0].stat.exists|default(False)) or
  43. (not etcdcert.results[1].stat.exists|default(False)) or
  44. (etcdcert.results[1].stat.checksum|default('') != etcdcert_master.results[loop.index].stat.checksum|default('')) -%}
  45. {%- set _ = certs.update({'sync': True}) -%}
  46. {% endif %}
  47. {% endif %}
  48. {%- endfor -%}
  49. {{ certs.sync }}