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.

50 lines
1.6 KiB

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