From 864f554a72688a9015a0e790605036671ca95058 Mon Sep 17 00:00:00 2001 From: portdirect Date: Mon, 20 Nov 2017 15:38:09 -0500 Subject: [PATCH] KubeADM: Move shell commands to use bash and set env vars This PS moves the shell module invocations to use bash and set the required env vars explicity. This can seolve some issues on ubuntu workstation hosts which uses dash for shell commands by default. Change-Id: Ieb440e421d9d95676719d66fb4c787f88a9d8a2b --- .../playbooks/roles/clean-host/tasks/main.yaml | 4 ++++ .../deploy-kubeadm-master/tasks/main.yaml | 18 +++++++++++++++--- .../tasks/wait-for-kube-system-namespace.yaml | 6 +++++- .../roles/deploy-kubelet/tasks/kubelet.yaml | 2 ++ .../roles/deploy-kubelet/tasks/setup-dns.yaml | 2 ++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/clean-host/tasks/main.yaml b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/clean-host/tasks/main.yaml index 36297bbe6..abe489895 100644 --- a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/clean-host/tasks/main.yaml +++ b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/clean-host/tasks/main.yaml @@ -29,6 +29,8 @@ - name: clean | kube | removing any old docker containers ignore_errors: yes shell: MY_CONTAINER_ID=$(docker inspect --format {% raw %}'{{ .Id }}'{% endraw %} "{{ my_container_name }}"); docker ps --all --no-trunc --quiet | awk '!'"/${MY_CONTAINER_ID}/ { print \$1 }" | xargs -r -l1 -P16 docker rm -f + args: + executable: /bin/bash - name: clean | kube | remove any mounts ignore_errors: yes @@ -36,6 +38,8 @@ for MOUNT in $(findmnt --df --output TARGET | grep "^/var/lib/kubelet"); do umount --force $MOUNT done + args: + executable: /bin/bash - name: clean | kube | remove dirs file: diff --git a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/main.yaml b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/main.yaml index 8b16c132a..5d3f489a4 100644 --- a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/main.yaml +++ b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/main.yaml @@ -84,17 +84,25 @@ delegate_to: 127.0.0.1 block: - name: wait for kube api - shell: export KUBECONFIG=/mnt/rootfs/etc/kubernetes/admin.conf; python /usr/bin/test-kube-api.py + shell: python /usr/bin/test-kube-api.py register: task_result until: task_result.rc == 0 retries: 120 delay: 5 + environment: + KUBECONFIG: '/mnt/rootfs/etc/kubernetes/admin.conf' + args: + executable: /bin/bash - name: wait for node to come online - shell: export KUBECONFIG=/mnt/rootfs/etc/kubernetes/admin.conf; kubectl get node "{{ kubeadm_node_hostname }}" --no-headers | gawk '{ print $2 }' | grep -q '\(^Ready\)\|\(^NotReady\)' + shell: kubectl get node "{{ kubeadm_node_hostname }}" --no-headers | gawk '{ print $2 }' | grep -q '\(^Ready\)\|\(^NotReady\)' register: task_result until: task_result.rc == 0 retries: 120 delay: 5 + environment: + KUBECONFIG: '/mnt/rootfs/etc/kubernetes/admin.conf' + args: + executable: /bin/bash - include_tasks: wait-for-kube-system-namespace.yaml - name: deploying kube-proxy @@ -107,11 +115,15 @@ delegate_to: 127.0.0.1 block: - name: wait for node to be ready - shell: export KUBECONFIG=/mnt/rootfs/etc/kubernetes/admin.conf; kubectl get node "{{ kubeadm_node_hostname }}" --no-headers | gawk '{ print $2 }' | grep -q '^Ready' + shell: kubectl get node "{{ kubeadm_node_hostname }}" --no-headers | gawk '{ print $2 }' | grep -q '^Ready' register: task_result until: task_result.rc == 0 retries: 120 delay: 5 + environment: + KUBECONFIG: '/mnt/rootfs/etc/kubernetes/admin.conf' + args: + executable: /bin/bash - include_tasks: wait-for-kube-system-namespace.yaml # - name: deploying kube-dns addon diff --git a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/wait-for-kube-system-namespace.yaml b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/wait-for-kube-system-namespace.yaml index 5b188c2db..7b83211ff 100644 --- a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/wait-for-kube-system-namespace.yaml +++ b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubeadm-master/tasks/wait-for-kube-system-namespace.yaml @@ -14,8 +14,12 @@ - name: wait for kube pods to all be running in kube-system namespace delegate_to: 127.0.0.1 - shell: export KUBECONFIG=/mnt/rootfs/etc/kubernetes/admin.conf; /usr/bin/test-kube-pods-ready kube-system + shell: /usr/bin/test-kube-pods-ready kube-system register: task_result until: task_result.rc == 0 retries: 120 delay: 5 + environment: + KUBECONFIG: '/mnt/rootfs/etc/kubernetes/admin.conf' + args: + executable: /bin/bash diff --git a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/kubelet.yaml b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/kubelet.yaml index b7cea4731..caa550378 100644 --- a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/kubelet.yaml +++ b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/kubelet.yaml @@ -56,6 +56,8 @@ - name: docker | getting cgroup driver info shell: docker info | awk '/^Cgroup Driver:/ { print $NF }' register: docker_cgroup_driver + args: + executable: /bin/bash - name: setting kublet cgroup driver set_fact: kubelet_cgroup_driver: "{{ docker_cgroup_driver.stdout }}" diff --git a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/setup-dns.yaml b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/setup-dns.yaml index 6eb0901e3..b6d708606 100644 --- a/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/setup-dns.yaml +++ b/tools/images/kubeadm-aio/assets/opt/playbooks/roles/deploy-kubelet/tasks/setup-dns.yaml @@ -47,3 +47,5 @@ until: task_result.rc == 0 retries: 120 delay: 5 + args: + executable: /bin/bash