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.

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