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.

97 lines
3.3 KiB

  1. ---
  2. - name: Gen_certs | write openssl config
  3. template:
  4. src: "openssl.conf.j2"
  5. dest: "{{ kube_config_dir }}/openssl.conf"
  6. run_once: yes
  7. delegate_to: "{{groups['kube-master'][0]}}"
  8. when: gen_certs|default(false)
  9. - name: Gen_certs | copy certs generation script
  10. copy:
  11. src: "make-ssl.sh"
  12. dest: "{{ kube_script_dir }}/make-ssl.sh"
  13. mode: 0700
  14. run_once: yes
  15. delegate_to: "{{groups['kube-master'][0]}}"
  16. when: gen_certs|default(false)
  17. - name: Gen_certs | run cert generation script
  18. command: "{{ kube_script_dir }}/make-ssl.sh -f {{ kube_config_dir }}/openssl.conf -d {{ kube_cert_dir }}"
  19. run_once: yes
  20. delegate_to: "{{groups['kube-master'][0]}}"
  21. when: gen_certs|default(false)
  22. notify: set secret_changed
  23. - set_fact:
  24. master_certs: ['ca-key.pem', 'admin.pem', 'admin-key.pem', 'apiserver-key.pem', 'apiserver.pem']
  25. node_certs: ['ca.pem', 'node.pem', 'node-key.pem']
  26. tags: facts
  27. - name: Gen_certs | Gather master certs
  28. shell: "tar cfz - -C {{ kube_cert_dir }} {{ master_certs|join(' ') }} {{ node_certs|join(' ') }} | base64 --wrap=0"
  29. register: master_cert_data
  30. delegate_to: "{{groups['kube-master'][0]}}"
  31. run_once: true
  32. when: sync_certs|default(false)
  33. - name: Gen_certs | Gather node certs
  34. shell: "tar cfz - -C {{ kube_cert_dir }} {{ node_certs|join(' ') }} | base64 --wrap=0"
  35. register: node_cert_data
  36. delegate_to: "{{groups['kube-master'][0]}}"
  37. run_once: true
  38. when: sync_certs|default(false)
  39. - name: Gen_certs | Copy certs on masters
  40. shell: "echo '{{master_cert_data.stdout|quote}}' | base64 -d | tar xz -C {{ kube_cert_dir }}"
  41. changed_when: false
  42. when: inventory_hostname in groups['kube-master'] and sync_certs|default(false) and
  43. inventory_hostname != groups['kube-master'][0]
  44. - name: Gen_certs | Copy certs on nodes
  45. shell: "echo '{{node_cert_data.stdout|quote}}' | base64 -d | tar xz -C {{ kube_cert_dir }}"
  46. changed_when: false
  47. when: (inventory_hostname in groups['kube-node'] or
  48. (peer_with_calico_rr and inventory_hostname in groups['calico-rr'])) and
  49. sync_certs|default(false) and
  50. inventory_hostname != groups['kube-master'][0]
  51. - name: Gen_certs | check certificate permissions
  52. file:
  53. path={{ kube_cert_dir }}
  54. group={{ kube_cert_group }}
  55. owner=kube
  56. recurse=yes
  57. - name: Gen_certs | set permissions on keys
  58. shell: chmod 0600 {{ kube_cert_dir}}/*key.pem
  59. when: inventory_hostname in groups['kube-master']
  60. changed_when: false
  61. - name: Gen_certs | target ca-certificates path
  62. set_fact:
  63. ca_cert_path: |-
  64. {% if ansible_os_family == "Debian" -%}
  65. /usr/local/share/ca-certificates/kube-ca.crt
  66. {%- elif ansible_os_family == "RedHat" -%}
  67. /etc/pki/ca-trust/source/anchors/kube-ca.crt
  68. {%- elif ansible_os_family == "CoreOS" -%}
  69. /etc/ssl/certs/kube-ca.pem
  70. {%- endif %}
  71. tags: facts
  72. - name: Gen_certs | add CA to trusted CA dir
  73. copy:
  74. src: "{{ kube_cert_dir }}/ca.pem"
  75. dest: "{{ ca_cert_path }}"
  76. remote_src: true
  77. register: kube_ca_cert
  78. - name: Gen_certs | update ca-certificates (Debian/Ubuntu/CoreOS)
  79. command: update-ca-certificates
  80. when: kube_ca_cert.changed and ansible_os_family in ["Debian", "CoreOS"]
  81. - name: Gen_certs | update ca-certificates (RedHat)
  82. command: update-ca-trust extract
  83. when: kube_ca_cert.changed and ansible_os_family == "RedHat"