---
# Copyright kubeinit contributors
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Install the simple app
block:
- name: Create the sampleapp template file
ansible.builtin.template:
src: "sampleapp.yml.j2"
dest: "~/sampleapp.yml"
mode: "0755"
- name: Install the sample app
ansible.builtin.shell: |
set -o pipefail
kubectl create namespace sampleapp
kubectl apply -f ~/sampleapp.yml
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
delegate_to: "{{ kubeinit_provision_service_node }}"
- name: Wait until pods are created
ansible.builtin.shell: |
set -o pipefail
kubectl get pods --namespace=sampleapp | grep sampleapp
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
retries: 60
delay: 5
until: _result.stdout_lines | list | length == kubeinit_apps_sampleapp_replicas|int
delegate_to: "{{ kubeinit_provision_service_node }}"
- name: Wait until pods are running
ansible.builtin.shell: |
set -o pipefail
kubectl get pods --namespace=sampleapp | grep Running
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
retries: 60
delay: 5
until: _result.stdout_lines | list | length == kubeinit_apps_sampleapp_replicas|int
delegate_to: "{{ kubeinit_provision_service_node }}"
rescue:
- name: Get some debugging information
ansible.builtin.shell: |
set -o pipefail
echo "********************"
echo "***"
echo "*** Describe the first sampleapp container information"
echo "***"
echo "********************"
kubectl describe pod $(kubectl get pods --namespace=sampleapp -o json | jq .items[0].metadata.name | tr -d '"') --namespace=sampleapp
echo "********************"
echo "***"
echo "*** Describe the first sampleapp container logs"
echo "***"
echo "********************"
kubectl logs $(kubectl get pods --namespace=sampleapp -o json | jq .items[0].metadata.name | tr -d '"') --namespace=sampleapp --previous
echo "********************"
echo "***"
echo "*** Get the first controller node name"
echo "***"
echo "********************"
kubectl get nodes -o json | jq .items[0].metadata.name
echo "********************"
echo "***"
echo "*** Get the first controller node taints"
echo "***"
echo "********************"
kubectl get nodes -o json | jq .items[0].spec.taints
echo "********************"
echo "***"
echo "*** Describe the first controller node info"
echo "***"
echo "********************"
kubectl describe node $(kubectl get nodes -o json | jq .items[0].metadata.name | tr -d '"')
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
delegate_to: "{{ kubeinit_provision_service_node }}"
- name: Force fail
ansible.builtin.fail:
msg: The sampleapp deployment failed, the deployment must fail
- name: Delete the sampleapp
ansible.builtin.shell: |
set -o pipefail
kubectl delete namespace sampleapp --force --grace-period=0 --wait=false
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
delegate_to: "{{ kubeinit_provision_service_node }}"