109 lines
3.6 KiB
YAML
109 lines
3.6 KiB
YAML
---
|
|
- hosts:
|
|
- master
|
|
- worker
|
|
become: true
|
|
gather_facts: true
|
|
any_errors_fatal: true
|
|
pre_tasks:
|
|
- name: Pausing for 5 seconds...
|
|
ansible.builtin.pause:
|
|
seconds: 5
|
|
tasks:
|
|
- name: Install Kubernetes
|
|
ansible.builtin.include_role:
|
|
name: xanmanning.k3s
|
|
public: true
|
|
vars:
|
|
k3s_state: installed
|
|
|
|
- name: Get absolute path to this Git repository
|
|
delegate_to: localhost
|
|
become: false
|
|
run_once: true
|
|
check_mode: false
|
|
ansible.builtin.command: |-
|
|
git rev-parse --show-toplevel
|
|
register: repo_abs_path
|
|
|
|
- name: Copy kubeconfig project directory
|
|
run_once: true
|
|
ansible.builtin.fetch:
|
|
src: "/etc/rancher/k3s/k3s.yaml"
|
|
dest: "{{ repo_abs_path.stdout }}/kubeconfig"
|
|
flat: true
|
|
when:
|
|
- k3s_control_node is defined
|
|
- k3s_control_node
|
|
|
|
- name: Update kubeconfig with the correct IPv4 address
|
|
delegate_to: localhost
|
|
become: false
|
|
run_once: true
|
|
ansible.builtin.replace:
|
|
path: "{{ repo_abs_path.stdout }}/kubeconfig"
|
|
regexp: "https://127.0.0.1:6443"
|
|
replace: "https://{{ k3s_registration_address }}:6443"
|
|
|
|
- name: Resource Readiness Check
|
|
run_once: true
|
|
kubernetes.core.k8s_info:
|
|
kubeconfig: /etc/rancher/k3s/k3s.yaml
|
|
kind: "{{ item.kind }}"
|
|
name: "{{ item.name }}"
|
|
namespace: "{{ item.namespace | default('') }}"
|
|
wait: true
|
|
wait_sleep: 10
|
|
wait_timeout: 360
|
|
loop:
|
|
- kind: Deployment
|
|
name: tigera-operator
|
|
namespace: tigera-operator
|
|
- kind: DaemonSet
|
|
name: kube-vip
|
|
namespace: kube-system
|
|
- kind: Installation
|
|
name: default
|
|
- kind: CustomResourceDefinition
|
|
name: alertmanagerconfigs.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: alertmanagers.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: podmonitors.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: probes.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: prometheuses.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: prometheusrules.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: servicemonitors.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: thanosrulers.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: scrapeconfigs.monitoring.coreos.com
|
|
- kind: CustomResourceDefinition
|
|
name: prometheusagents.monitoring.coreos.com
|
|
when:
|
|
- k3s_server_manifests_templates | length > 0
|
|
or k3s_server_manifests_urls | length > 0
|
|
- k3s_control_node is defined
|
|
- k3s_control_node
|
|
|
|
# NOTE
|
|
# Cleaning up the manifests from the /var/lib/rancher/k3s/server/manifests directory
|
|
# is needed because k3s has an awesome "feature" to always re-deploy them when the k3s
|
|
# service is restarted. Removing them does not uninstall the manifests from your cluster.
|
|
|
|
- name: Remove deployed manifest templates
|
|
ansible.builtin.file:
|
|
path: "{{ k3s_server_manifests_dir }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
|
|
state: absent
|
|
loop: "{{ k3s_server_manifests_templates | default([]) }}"
|
|
|
|
- name: Remove deployed manifest urls
|
|
ansible.builtin.file:
|
|
path: "{{ k3s_server_manifests_dir }}/{{ item.filename }}"
|
|
state: absent
|
|
loop: "{{ k3s_server_manifests_urls | default([]) }}"
|