Playbook #1

/root/kubeinit/ci/builds/6mbKNrxD/0/kubeinit/kubeinit/kubeinit-aux/kubeinit/playbook.yml

Report Status CLI Date Duration Controller User Versions Hosts Plays Tasks Results Files Records
31 Oct 2023 08:44:29 +0000 00:45:59.97 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 9 7 1091 1091 53 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_apps/tasks/sampleapp.yml

---
# 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 }}"