aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/k8s/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/k8s/tasks')
-rw-r--r--ansible/roles/k8s/tasks/install_k3s_master.yml20
-rw-r--r--ansible/roles/k8s/tasks/install_k3s_worker.yml19
-rw-r--r--ansible/roles/k8s/tasks/main.yml8
3 files changed, 47 insertions, 0 deletions
diff --git a/ansible/roles/k8s/tasks/install_k3s_master.yml b/ansible/roles/k8s/tasks/install_k3s_master.yml
new file mode 100644
index 0000000..71d880e
--- /dev/null
+++ b/ansible/roles/k8s/tasks/install_k3s_master.yml
@@ -0,0 +1,20 @@
+---
+- name: Download k3s installer
+ ansible.builtin.get_url:
+ url: https://get.k3s.io
+ dest: /tmp/install_k3s.sh
+ mode: '0755'
+
+- name: Install k3s server
+ ansible.builtin.command: /tmp/install_k3s.sh server --cluster-init
+ become: true
+
+- name: Retrieve k3s token
+ ansible.builtin.slurp:
+ path: /var/lib/rancher/k3s/server/node-token
+ register: k3s_token_file
+
+- name: Set k3s token as a fact, for workers
+ ansible.builtin.set_fact:
+ k3s_token: "{{ k3s_token_file.content | b64decode }}"
+...
diff --git a/ansible/roles/k8s/tasks/install_k3s_worker.yml b/ansible/roles/k8s/tasks/install_k3s_worker.yml
new file mode 100644
index 0000000..ffe2af0
--- /dev/null
+++ b/ansible/roles/k8s/tasks/install_k3s_worker.yml
@@ -0,0 +1,19 @@
+---
+- name: Retrieve k3s token and master IP from master node
+ ansible.builtin.set_fact:
+ k3s_token: "{{ hostvars[groups['tag_k3s_master'][0]].k3s_token }}"
+ k3s_master_ip: "{{ hostvars[groups['tag_k3s_master'][0]].ansible_default_ipv4.address }}"
+
+- name: Download k3s installation script
+ ansible.builtin.get_url:
+ url: https://get.k3s.io
+ dest: /tmp/install_k3s.sh
+ mode: '0755'
+
+- name: Install k3s agent
+ ansible.builtin.command: >
+ /tmp/install_k3s.sh agent
+ --server https://{{ k3s_master_ip }}:6443
+ --token {{ k3s_token }}
+ become: true
+...
diff --git a/ansible/roles/k8s/tasks/main.yml b/ansible/roles/k8s/tasks/main.yml
index c784c7c..fb58c1b 100644
--- a/ansible/roles/k8s/tasks/main.yml
+++ b/ansible/roles/k8s/tasks/main.yml
@@ -1,4 +1,12 @@
---
- name: Include UFW tasks
ansible.builtin.include_tasks: ufw.yml
+
+- name: Install k3s on master nodes
+ ansible.builtin.include_tasks: install_k3s_master.yml
+ when: inventory_hostname in groups['tag_k3s_master']
+
+- name: Install k3s on worker nodes
+ ansible.builtin.include_tasks: install_k3s_worker.yml
+ when: inventory_hostname in groups['tag_k3s_worker']
...