From 5f1d1bfa8a14358820b30152f4dcbc809719659a Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Fri, 19 Aug 2022 12:55:53 +0200 Subject: [PATCH] Change order (test timing of handler) --- .../roles/metacluster/tasks/main.yml | 154 +++++++++--------- 1 file changed, 75 insertions(+), 79 deletions(-) diff --git a/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml b/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml index 79eb11f..bf1935a 100644 --- a/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml +++ b/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml @@ -1,91 +1,87 @@ -- block: +- name: Gather service facts + ansible.builtin.service_facts: + # Module requires no attributes - - name: Gather service facts - ansible.builtin.service_facts: - # Module requires no attributes +- name: Install K3s + ansible.builtin.command: + cmd: ./install.sh + chdir: /opt/metacluster/k3s + environment: + INSTALL_K3S_SKIP_DOWNLOAD: 'true' + INSTALL_K3S_EXEC: 'server --cluster-init --disable local-storage' + when: ansible_facts.services['k3s.service'] is undefined - - name: Install K3s - ansible.builtin.command: - cmd: ./install.sh - chdir: /opt/metacluster/k3s - environment: - INSTALL_K3S_SKIP_DOWNLOAD: 'true' - INSTALL_K3S_EXEC: 'server --cluster-init --disable local-storage' - when: ansible_facts.services['k3s.service'] is undefined - - - name: Ensure API availability - ansible.utils.cli_parse: - command: curl -k https://{{ vapp['guestinfo.ipaddress'] }}:6443/livez?verbose - parser: - name: ansible.utils.json - set_fact: api_readycheck - ignore_errors: yes - until: api_readycheck.apiVersion is defined - retries: 3 - delay: 30 - - - name: Initialize tempfile - ansible.builtin.tempfile: - state: file - register: kubeconfig - - - name: Retrieve kubeconfig - ansible.builtin.command: - cmd: kubectl config view --raw - register: kubectl_config - - - name: Store kubeconfig in tempfile - ansible.builtin.copy: - dest: "{{ kubeconfig.path }}" - content: "{{ kubectl_config.stdout }}" - mode: 0600 - no_log: true - - - name: Configure traefik dashboard ingress - ansible.builtin.template: - src: ingressroute.j2 - dest: /var/lib/rancher/k3s/server/manifests/{{ _template.name }}-manifest.yaml - owner: root - group: root - mode: 0600 - vars: - _template: - name: traefik-dashboard - namespace: kube-system - config: |2 - entryPoints: - - web - - websecure - routes: - - kind: Rule - match: Host(`ingress.{{ vapp['metacluster.fqdn'] }}`) - services: - - kind: TraefikService - name: api@internal - notify: - - Apply manifests - - - name: Trigger handlers - ansible.builtin.meta: flush_handlers +- name: Ensure API availability + ansible.utils.cli_parse: + command: curl -k https://{{ vapp['guestinfo.ipaddress'] }}:6443/livez?verbose + parser: + name: ansible.utils.json + set_fact: api_readycheck + ignore_errors: yes + until: api_readycheck.apiVersion is defined + retries: 3 + delay: 30 - name: Install kubectl tab-completion ansible.builtin.shell: cmd: kubectl completion bash | tee /etc/bash_completion.d/kubectl -- block: +- name: Extract container images + ansible.builtin.unarchive: + src: /opt/metacluster/container-images/image-tarballs.tgz + dest: /opt/metacluster/container-images + list_files: yes + register: imagetarballs - - name: Extract container images - ansible.builtin.unarchive: - src: /opt/metacluster/container-images/image-tarballs.tgz - dest: /opt/metacluster/container-images - list_files: yes - register: imagetarballs +- name: Import container images + ansible.builtin.command: + cmd: k3s ctr image import {{ item }} + chdir: /opt/metacluster/container-images + loop: "{{ imagetarballs.files }}" - - name: Import container images - ansible.builtin.command: - cmd: k3s ctr image import {{ item }} - chdir: /opt/metacluster/container-images - loop: "{{ imagetarballs.files }}" +- name: Initialize tempfile + ansible.builtin.tempfile: + state: file + register: kubeconfig + +- name: Retrieve kubeconfig + ansible.builtin.command: + cmd: kubectl config view --raw + register: kubectl_config + +- name: Store kubeconfig in tempfile + ansible.builtin.copy: + dest: "{{ kubeconfig.path }}" + content: "{{ kubectl_config.stdout }}" + mode: 0600 + no_log: true + +- name: Configure traefik dashboard ingress + ansible.builtin.template: + src: ingressroute.j2 + dest: /var/lib/rancher/k3s/server/manifests/{{ _template.name }}-manifest.yaml + owner: root + group: root + mode: 0600 + vars: + _template: + name: traefik-dashboard + namespace: kube-system + config: |2 + entryPoints: + - web + - websecure + routes: + - kind: Rule + match: Host(`ingress.{{ vapp['metacluster.fqdn'] }}`) + services: + - kind: TraefikService + name: api@internal + notify: + - Apply manifests + +- name: Trigger handlers + ansible.builtin.meta: flush_handlers - name: Create component entries in /etc/hosts ansible.builtin.lineinfile: