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.

107 lines
3.8 KiB

  1. ---
  2. - name: "Gen_helm_tiller_certs | Create helm config directory (on {{groups['kube-master'][0]}})"
  3. run_once: yes
  4. delegate_to: "{{groups['kube-master'][0]}}"
  5. file:
  6. path: "{{ helm_config_dir }}"
  7. state: directory
  8. owner: kube
  9. - name: "Gen_helm_tiller_certs | Create helm script directory (on {{groups['kube-master'][0]}})"
  10. run_once: yes
  11. delegate_to: "{{groups['kube-master'][0]}}"
  12. file:
  13. path: "{{ helm_script_dir }}"
  14. state: directory
  15. owner: kube
  16. - name: Gen_helm_tiller_certs | Copy certs generation script
  17. run_once: yes
  18. delegate_to: "{{groups['kube-master'][0]}}"
  19. template:
  20. src: "helm-make-ssl.sh.j2"
  21. dest: "{{ helm_script_dir }}/helm-make-ssl.sh"
  22. mode: 0700
  23. - name: "Check_helm_certs | check if helm client certs have already been generated on first master (on {{groups['kube-master'][0]}})"
  24. find:
  25. paths: "{{ helm_home_dir }}"
  26. patterns: "*.pem"
  27. get_checksum: true
  28. delegate_to: "{{groups['kube-master'][0]}}"
  29. register: helmcert_master
  30. run_once: true
  31. - name: Gen_helm_tiller_certs | run cert generation script
  32. run_once: yes
  33. delegate_to: "{{groups['kube-master'][0]}}"
  34. command: "{{ helm_script_dir }}/helm-make-ssl.sh -e {{ helm_home_dir }} -d {{ helm_tiller_cert_dir }}"
  35. - set_fact:
  36. helm_client_certs: ['ca.pem', 'cert.pem', 'key.pem']
  37. - name: "Check_helm_client_certs | check if a cert already exists on master node"
  38. find:
  39. paths: "{{ helm_home_dir }}"
  40. patterns: "*.pem"
  41. get_checksum: true
  42. register: helmcert_node
  43. when: inventory_hostname != groups['kube-master'][0]
  44. - name: "Check_helm_client_certs | Set 'sync_helm_certs' to true on masters"
  45. set_fact:
  46. sync_helm_certs: true
  47. when: inventory_hostname != groups['kube-master'][0] and
  48. (not item in helmcert_node.files | map(attribute='path') | map("basename") | list or
  49. helmcert_node.files | selectattr("path", "equalto", "{{ helm_home_dir }}/{{ item }}") | map(attribute="checksum")|first|default('') != helmcert_master.files | selectattr("path", "equalto", "{{ helm_home_dir }}/{{ item }}") | map(attribute="checksum")|first|default(''))
  50. with_items:
  51. - "{{ helm_client_certs }}"
  52. - name: Gen_helm_tiller_certs | Gather helm client certs
  53. shell: "tar cfz - -C {{ helm_home_dir }} -T /dev/stdin <<< {{ helm_client_certs|join(' ') }} | base64 --wrap=0"
  54. args:
  55. executable: /bin/bash
  56. no_log: true
  57. register: helm_client_cert_data
  58. check_mode: no
  59. delegate_to: "{{groups['kube-master'][0]}}"
  60. when: sync_helm_certs|default(false) and inventory_hostname != groups['kube-master'][0]
  61. - name: Gen_helm_tiller_certs | Use tempfile for unpacking certs on masters
  62. tempfile:
  63. state: file
  64. path: /tmp
  65. prefix: helmcertsXXXXX
  66. suffix: tar.gz
  67. register: helm_cert_tempfile
  68. when: sync_helm_certs|default(false) and inventory_hostname != groups['kube-master'][0]
  69. - name: Gen_helm_tiller_certs | Write helm client certs to tempfile
  70. copy:
  71. content: "{{helm_client_cert_data.stdout}}"
  72. dest: "{{helm_cert_tempfile.path}}"
  73. owner: root
  74. mode: "0600"
  75. when: sync_helm_certs|default(false) and inventory_hostname != groups['kube-master'][0]
  76. - name: Gen_helm_tiller_certs | Unpack helm certs on masters
  77. shell: "base64 -d < {{ helm_cert_tempfile.path }} | tar xz -C {{ helm_home_dir }}"
  78. no_log: true
  79. changed_when: false
  80. check_mode: no
  81. when: sync_helm_certs|default(false) and inventory_hostname != groups['kube-master'][0]
  82. - name: Gen_helm_tiller_certs | Cleanup tempfile on masters
  83. file:
  84. path: "{{helm_cert_tempfile.path}}"
  85. state: absent
  86. when: sync_helm_certs|default(false) and inventory_hostname != groups['kube-master'][0]
  87. - name: Gen_certs | check certificate permissions
  88. file:
  89. path: "{{ helm_home_dir }}"
  90. group: "{{ helm_cert_group }}"
  91. state: directory
  92. owner: "{{ helm_cert_owner }}"
  93. mode: "u=rwX,g-rwx,o-rwx"
  94. recurse: yes