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.

130 lines
3.6 KiB

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