c12s-kubespray/roles/kubernetes/client/tasks/main.yml
Michael Oglesby 07ecef86e3 Replace fetch with synchronize due to memory error (#5084)
Fix for Kubespray Issue #5059 (https://github.com/kubernetes-sigs/kubespray/issues/5059). There is a known issue with the 'fetch' module that will sometimes lead to it failing with a memory error. See ansible/ansible#11702 (https://github.com/ansible/ansible/issues/11702). I encountered this issue with the "Copy kubectl binary to ansible host" task in kubespray/roles/kubernetes/client/tasks/main.yml, and it caused my entire deployment to error out (see "Output of ansible run" above). Replacing 'fetch' with 'synchronize' fixes this issue.
2019-08-22 02:40:32 -07:00

111 lines
3.3 KiB
YAML

---
- name: Set external kube-apiserver endpoint
set_fact:
external_apiserver_address: >-
{%- if loadbalancer_apiserver is defined and loadbalancer_apiserver.address is defined -%}
{{ loadbalancer_apiserver.address }}
{%- else -%}
{{ kube_apiserver_access_address }}
{%- endif -%}
external_apiserver_port: >-
{%- if loadbalancer_apiserver is defined and loadbalancer_apiserver.address is defined and loadbalancer_apiserver.port is defined -%}
{{ loadbalancer_apiserver.port|default(kube_apiserver_port) }}
{%- else -%}
{{ kube_apiserver_port }}
{%- endif -%}
tags:
- facts
- name: Create kube config dir for current/ansible become user
file:
path: "{{ ansible_env.HOME | default('/root') }}/.kube"
mode: "0700"
state: directory
- name: Copy admin kubeconfig to current/ansible become user home
copy:
src: "{{ kube_config_dir }}/admin.conf"
dest: "{{ ansible_env.HOME | default('/root') }}/.kube/config"
remote_src: yes
mode: "0600"
backup: yes
- 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)
- name: Wait for k8s apiserver
wait_for:
host: "{{ kube_apiserver_access_address }}"
port: "{{ kube_apiserver_port }}"
timeout: 180
# NOTE(mattymo): Please forgive this workaround
- name: Generate admin kubeconfig with external api endpoint
shell: >-
{% if kubeadm_version is version('v1.14.0', '>=') %}
mkdir -p {{ kube_config_dir }}/external_kubeconfig &&
{% endif %}
{{ 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 %}
kubeconfig user
--client-name kubernetes-admin
--org system:masters
{% endif %}
--cert-dir {{ kube_cert_dir }}
--apiserver-advertise-address {{ external_apiserver_address }}
--apiserver-bind-port {{ external_apiserver_port }}
{% if kubeadm_version is version('v1.14.0', '>=') %}
>/dev/null && cat {{ kube_config_dir }}/external_kubeconfig/admin.conf &&
rm -rf {{ kube_config_dir }}/external_kubeconfig
{% endif %}
environment: "{{ proxy_env }}"
run_once: yes
register: admin_kubeconfig
- name: Write admin kubeconfig on ansible host
copy:
content: "{{ admin_kubeconfig.stdout }}"
dest: "{{ artifacts_dir }}/admin.conf"
mode: 0640
delegate_to: localhost
become: no
run_once: yes
when: kubeconfig_localhost|default(false)
- name: Copy kubectl binary to ansible host
synchronize:
src: "{{ bin_dir }}/kubectl"
dest: "{{ artifacts_dir }}/kubectl"
become: no
run_once: yes
when: kubectl_localhost|default(false)
- name: create helper script kubectl.sh on ansible host
copy:
content: |
#!/bin/bash
./kubectl --kubeconfig=${BASH_SOURCE%/*}/admin.conf $@
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)