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.

116 lines
3.4 KiB

  1. ---
  2. - import_tasks: check-certs.yml
  3. tags:
  4. - k8s-secrets
  5. - facts
  6. - import_tasks: check-tokens.yml
  7. tags:
  8. - k8s-secrets
  9. - facts
  10. - name: Make sure the certificate directory exits
  11. file:
  12. path: "{{ kube_cert_dir }}"
  13. state: directory
  14. mode: o-rwx
  15. group: "{{ kube_cert_group }}"
  16. - name: Make sure the tokens directory exits
  17. file:
  18. path: "{{ kube_token_dir }}"
  19. state: directory
  20. mode: o-rwx
  21. group: "{{ kube_cert_group }}"
  22. #
  23. # The following directory creates make sure that the directories
  24. # exist on the first master for cases where the first master isn't
  25. # being run.
  26. #
  27. - name: "Gen_certs | Create kubernetes config directory (on {{groups['kube-master'][0]}})"
  28. file:
  29. path: "{{ kube_config_dir }}"
  30. state: directory
  31. owner: kube
  32. run_once: yes
  33. delegate_to: "{{groups['kube-master'][0]}}"
  34. when: gen_certs|default(false) or gen_tokens|default(false)
  35. tags:
  36. - kubelet
  37. - k8s-secrets
  38. - kube-controller-manager
  39. - kube-apiserver
  40. - bootstrap-os
  41. - apps
  42. - network
  43. - master
  44. - node
  45. - name: "Gen_certs | Create kubernetes script directory (on {{groups['kube-master'][0]}})"
  46. file:
  47. path: "{{ kube_script_dir }}"
  48. state: directory
  49. owner: kube
  50. run_once: yes
  51. delegate_to: "{{groups['kube-master'][0]}}"
  52. when: gen_certs|default(false) or gen_tokens|default(false)
  53. tags:
  54. - k8s-secrets
  55. - bootstrap-os
  56. - name: "Get_tokens | Make sure the tokens directory exits (on {{groups['kube-master'][0]}})"
  57. file:
  58. path: "{{ kube_token_dir }}"
  59. state: directory
  60. mode: o-rwx
  61. group: "{{ kube_cert_group }}"
  62. run_once: yes
  63. delegate_to: "{{groups['kube-master'][0]}}"
  64. when: gen_tokens|default(false)
  65. - include_tasks: "gen_certs_{{ cert_management }}.yml"
  66. tags:
  67. - k8s-secrets
  68. - import_tasks: upd_ca_trust.yml
  69. tags:
  70. - k8s-secrets
  71. - name: "Gen_certs | Get certificate serials on kube masters"
  72. shell: "openssl x509 -in {{ kube_cert_dir }}/{{ item }} -noout -serial | cut -d= -f2"
  73. register: "master_certificate_serials"
  74. changed_when: false
  75. with_items:
  76. - "admin-{{ inventory_hostname }}.pem"
  77. - "apiserver.pem"
  78. - "kube-controller-manager.pem"
  79. - "kube-scheduler.pem"
  80. when: inventory_hostname in groups['kube-master']
  81. - name: "Gen_certs | set kube master certificate serial facts"
  82. set_fact:
  83. etcd_admin_cert_serial: "{{ master_certificate_serials.results[0].stdout|default() }}"
  84. apiserver_cert_serial: "{{ master_certificate_serials.results[1].stdout|default() }}"
  85. controller_manager_cert_serial: "{{ master_certificate_serials.results[2].stdout|default() }}"
  86. scheduler_cert_serial: "{{ master_certificate_serials.results[3].stdout|default() }}"
  87. when: inventory_hostname in groups['kube-master']
  88. - name: "Gen_certs | Get certificate serials on kube nodes"
  89. shell: "openssl x509 -in {{ kube_cert_dir }}/{{ item }} -noout -serial | cut -d= -f2"
  90. register: "node_certificate_serials"
  91. changed_when: false
  92. with_items:
  93. - "node-{{ inventory_hostname }}.pem"
  94. - "kube-proxy-{{ inventory_hostname }}.pem"
  95. when: inventory_hostname in groups['k8s-cluster']
  96. - name: "Gen_certs | set kube node certificate serial facts"
  97. set_fact:
  98. kubelet_cert_serial: "{{ node_certificate_serials.results[0].stdout|default() }}"
  99. kube_proxy_cert_serial: "{{ node_certificate_serials.results[1].stdout|default() }}"
  100. when: inventory_hostname in groups['k8s-cluster']
  101. - import_tasks: gen_tokens.yml
  102. tags:
  103. - k8s-secrets