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.

115 lines
3.6 KiB

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