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.

67 lines
2.0 KiB

  1. ---
  2. - name: Set first kube master
  3. set_fact:
  4. first_kube_master: "{{ hostvars[groups['kube-master'][0]]['access_ip'] | default(hostvars[groups['kube-master'][0]]['ip'] | default(hostvars[groups['kube-master'][0]]['ansible_default_ipv4']['address'])) }}"
  5. - name: Set external kube-apiserver endpoint
  6. set_fact:
  7. external_apiserver_endpoint: >-
  8. {%- if loadbalancer_apiserver is defined and loadbalancer_apiserver.port is defined -%}
  9. https://{{ apiserver_loadbalancer_domain_name|default('lb-apiserver.kubernetes.local') }}:{{ loadbalancer_apiserver.port|default(kube_apiserver_port) }}
  10. {%- else -%}
  11. https://{{ first_kube_master }}:{{ kube_apiserver_port }}
  12. {%- endif -%}
  13. tags:
  14. - facts
  15. - name: Gather certs for admin kubeconfig
  16. slurp:
  17. src: "{{ item }}"
  18. register: admin_certs
  19. with_items:
  20. - "{{ kube_cert_dir }}/ca.pem"
  21. - "{{ kube_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  22. - "{{ kube_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  23. when: not kubeadm_enabled|d(false)|bool
  24. - name: Write admin kubeconfig
  25. template:
  26. src: admin.conf.j2
  27. dest: "{{ kube_config_dir }}/admin.conf"
  28. owner: root
  29. group: "{{ kube_cert_group }}"
  30. mode: 0640
  31. when: not kubeadm_enabled|d(false)|bool
  32. - name: Create kube config dir
  33. file:
  34. path: "/root/.kube"
  35. mode: "0700"
  36. state: directory
  37. - name: Copy admin kubeconfig to root user home
  38. copy:
  39. src: "{{ kube_config_dir }}/admin.conf"
  40. dest: "/root/.kube/config"
  41. remote_src: yes
  42. mode: "0700"
  43. backup: yes
  44. - name: Copy admin kubeconfig to ansible host
  45. fetch:
  46. src: "{{ kube_config_dir }}/admin.conf"
  47. dest: "{{ artifacts_dir }}/admin.conf"
  48. flat: yes
  49. validate_checksum: no
  50. run_once: yes
  51. when: kubeconfig_localhost|default(false)
  52. - name: Copy kubectl binary to ansible host
  53. fetch:
  54. src: "{{ bin_dir }}/kubectl"
  55. dest: "{{ artifacts_dir }}/kubectl"
  56. flat: yes
  57. validate_checksum: no
  58. become: no
  59. run_once: yes
  60. when: kubectl_localhost|default(false)