2017-09-18 20:30:57 +08:00
|
|
|
---
|
|
|
|
- name: Set external kube-apiserver endpoint
|
|
|
|
set_fact:
|
2019-01-16 21:30:50 +08:00
|
|
|
external_apiserver_address: >-
|
2019-01-21 17:27:42 +08:00
|
|
|
{%- if loadbalancer_apiserver is defined and loadbalancer_apiserver.address is defined -%}
|
|
|
|
{{ loadbalancer_apiserver.address }}
|
2017-09-18 20:30:57 +08:00
|
|
|
{%- else -%}
|
2019-01-16 21:30:50 +08:00
|
|
|
{{ kube_apiserver_access_address }}
|
|
|
|
{%- endif -%}
|
|
|
|
external_apiserver_port: >-
|
2019-01-21 19:43:27 +08:00
|
|
|
{%- if loadbalancer_apiserver is defined and loadbalancer_apiserver.address is defined and loadbalancer_apiserver.port is defined -%}
|
2019-01-16 21:30:50 +08:00
|
|
|
{{ loadbalancer_apiserver.port|default(kube_apiserver_port) }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ kube_apiserver_port }}
|
2017-09-18 20:30:57 +08:00
|
|
|
{%- endif -%}
|
2017-10-05 15:43:04 +08:00
|
|
|
tags:
|
|
|
|
- facts
|
2017-09-18 20:30:57 +08:00
|
|
|
|
2019-06-06 17:06:11 +08:00
|
|
|
- name: Create kube config dir for current/ansible become user
|
2017-09-18 20:30:57 +08:00
|
|
|
file:
|
2019-06-06 17:06:11 +08:00
|
|
|
path: "{{ ansible_env.HOME | default('/root') }}/.kube"
|
2017-09-18 20:30:57 +08:00
|
|
|
mode: "0700"
|
|
|
|
state: directory
|
|
|
|
|
2019-06-06 17:06:11 +08:00
|
|
|
- name: Copy admin kubeconfig to current/ansible become user home
|
2017-09-18 20:30:57 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ kube_config_dir }}/admin.conf"
|
2019-06-06 17:06:11 +08:00
|
|
|
dest: "{{ ansible_env.HOME | default('/root') }}/.kube/config"
|
2017-09-18 20:30:57 +08:00
|
|
|
remote_src: yes
|
2018-05-14 17:29:48 +08:00
|
|
|
mode: "0600"
|
2017-09-18 20:30:57 +08:00
|
|
|
backup: yes
|
|
|
|
|
2019-01-28 17:59:15 +08:00
|
|
|
- name: Create kube artifacts dir
|
|
|
|
file:
|
|
|
|
path: "{{ artifacts_dir }}"
|
|
|
|
mode: "0750"
|
|
|
|
state: directory
|
|
|
|
delegate_to: localhost
|
|
|
|
become: no
|
|
|
|
run_once: yes
|
|
|
|
when: kubeconfig_localhost|default(false)
|
|
|
|
|
2019-04-19 21:01:54 +08:00
|
|
|
# NOTE(mattymo): Please forgive this workaround
|
2019-01-16 21:30:50 +08:00
|
|
|
- name: Generate admin kubeconfig with external api endpoint
|
|
|
|
shell: >-
|
2019-04-19 21:01:54 +08:00
|
|
|
{% if kubeadm_version is version('v1.14.0', '>=') %}
|
|
|
|
mkdir -p {{ kube_config_dir }}/external_kubeconfig &&
|
2019-01-16 21:30:50 +08:00
|
|
|
{% endif %}
|
2019-04-19 21:01:54 +08:00
|
|
|
{{ bin_dir }}/kubeadm
|
|
|
|
{% if kubeadm_version is version('v1.14.0', '>=') %}
|
|
|
|
init phase
|
|
|
|
{% elif kubeadm_version is version('v1.13.0', '>=') %}
|
|
|
|
alpha
|
|
|
|
{% else %}
|
|
|
|
alpha phase
|
|
|
|
{% endif %}
|
|
|
|
{% if kubeadm_version is version('v1.14.0', '>=') %}
|
|
|
|
kubeconfig admin
|
|
|
|
--kubeconfig-dir {{ kube_config_dir }}/external_kubeconfig
|
|
|
|
{% else %}
|
2019-01-16 21:30:50 +08:00
|
|
|
kubeconfig user
|
|
|
|
--client-name kubernetes-admin
|
|
|
|
--org system:masters
|
2019-04-19 21:01:54 +08:00
|
|
|
{% endif %}
|
2019-05-09 04:38:36 +08:00
|
|
|
--cert-dir {{ kube_cert_dir }}
|
2019-01-16 21:30:50 +08:00
|
|
|
--apiserver-advertise-address {{ external_apiserver_address }}
|
|
|
|
--apiserver-bind-port {{ external_apiserver_port }}
|
2019-04-19 21:01:54 +08:00
|
|
|
{% if kubeadm_version is version('v1.14.0', '>=') %}
|
2019-05-06 18:29:36 +08:00
|
|
|
>/dev/null && cat {{ kube_config_dir }}/external_kubeconfig/admin.conf &&
|
2019-04-19 21:01:54 +08:00
|
|
|
rm -rf {{ kube_config_dir }}/external_kubeconfig
|
|
|
|
{% endif %}
|
2019-03-26 18:03:19 +08:00
|
|
|
environment: "{{ proxy_env }}"
|
2019-01-16 21:30:50 +08:00
|
|
|
run_once: yes
|
|
|
|
register: admin_kubeconfig
|
|
|
|
|
|
|
|
- name: Write admin kubeconfig on ansible host
|
|
|
|
copy:
|
|
|
|
content: "{{ admin_kubeconfig.stdout }}"
|
2017-09-18 20:30:57 +08:00
|
|
|
dest: "{{ artifacts_dir }}/admin.conf"
|
2019-01-16 21:30:50 +08:00
|
|
|
mode: 0640
|
|
|
|
delegate_to: localhost
|
|
|
|
become: no
|
2017-09-18 20:30:57 +08:00
|
|
|
run_once: yes
|
|
|
|
when: kubeconfig_localhost|default(false)
|
|
|
|
|
|
|
|
- name: Copy kubectl binary to ansible host
|
|
|
|
fetch:
|
|
|
|
src: "{{ bin_dir }}/kubectl"
|
2018-04-09 18:19:26 +08:00
|
|
|
dest: "{{ artifacts_dir }}/kubectl"
|
2017-09-18 20:30:57 +08:00
|
|
|
flat: yes
|
|
|
|
validate_checksum: no
|
|
|
|
become: no
|
|
|
|
run_once: yes
|
|
|
|
when: kubectl_localhost|default(false)
|
2018-02-16 20:53:35 +08:00
|
|
|
|
|
|
|
- name: create helper script kubectl.sh on ansible host
|
|
|
|
copy:
|
|
|
|
content: |
|
|
|
|
#!/bin/bash
|
2018-11-20 10:28:51 +08:00
|
|
|
kubectl --kubeconfig=${BASH_SOURCE%/*}/admin.conf $@
|
2018-02-16 20:53:35 +08:00
|
|
|
dest: "{{ artifacts_dir }}/kubectl.sh"
|
|
|
|
mode: 0755
|
|
|
|
become: no
|
|
|
|
run_once: yes
|
|
|
|
delegate_to: localhost
|
|
|
|
when: kubectl_localhost|default(false) and kubeconfig_localhost|default(false)
|