aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/k8s/tasks/install_k3s_master.yml
blob: dfb416f0a823fff52c57dc01033e9694fdb508c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
- name: Ensure /opt/k3s directory exists
  ansible.builtin.file:
    path: /opt/k3s
    state: directory
    mode: '0755'

- name: Check if k3s installer script already exists
  ansible.builtin.stat:
    path: /opt/k3s/install_k3s.sh
  register: k3s_installer_script

- name: Download k3s installer if not already present
  ansible.builtin.get_url:
    url: https://get.k3s.io
    dest: /opt/k3s/install_k3s.sh
    mode: '0755'
  when: not k3s_installer_script.stat.exists

- name: Check if k3s is already installed (master)
  ansible.builtin.stat:
    path: /var/lib/rancher/k3s/server/node-token
  register: k3s_installed

- name: Install k3s server if not already installed
  ansible.builtin.command: /opt/k3s/install_k3s.sh server --cluster-init
  become: true
  when: not k3s_installed.stat.exists

- name: Retrieve k3s token
  ansible.builtin.slurp:
    path: /var/lib/rancher/k3s/server/node-token
  register: k3s_token_file
  when: not k3s_installed.stat.exists

- name: Set k3s token as a fact, for workers
  ansible.builtin.set_fact:
    k3s_token: "{{ k3s_token_file.content | b64decode }}"
  when: k3s_token_file is defined and k3s_token_file.content is defined
...