Skip to content

Commit 6d6bd2d

Browse files
committed
Refactored k9s install
1 parent 56c0d67 commit 6d6bd2d

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

ansible/extras.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@
3636
tasks:
3737
- import_role:
3838
name: persist_hostkeys
39+
40+
- name: Install k9s
41+
become: yes
42+
hosts: k9s
43+
tasks:
44+
- import_role:
45+
name: k9s

ansible/roles/k3s/tasks/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
mode: 0755
3434
remote_src: true
3535

36-
- name: k9s install
37-
ansible.builtin.include_role:
38-
name: k9s
36+
- name: Add k3s kubeconfig as environment variable
37+
ansible.builtin.lineinfile:
38+
path: /etc/environment
39+
line: "KUBECONFIG=/etc/rancher/k3s/k3s.yaml"
3940

4041
- name: Install ansible-init playbook for k3s agent or server activation
4142
copy:

ansible/roles/k9s/tasks/main.yml

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
---
2-
- name: Create install directory
3-
ansible.builtin.file:
4-
path: /root/k9s-temp
5-
state: directory
2+
3+
- name: Check if k9s is installed
4+
ansible.builtin.stat:
5+
path: "/usr/bin/k9s"
6+
register: result
67

7-
- name: Download k9s
8-
ansible.builtin.get_url:
9-
url: https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz
10-
dest: /root/k9s-temp/k9s_Linux_amd64.tar.gz
8+
- name: Install k9s and clean up temporary files
9+
block:
10+
- name: Create install directory
11+
ansible.builtin.file:
12+
path: /tmp/k9s
13+
state: directory
14+
owner: root
15+
group: root
16+
mode: "744"
17+
when: not result.stat.exists
1118

12-
- name: Unpack k9s binary
13-
ansible.builtin.unarchive:
14-
src: /root/k9s-temp/k9s_Linux_amd64.tar.gz
15-
dest: /root/k9s-temp
16-
remote_src: yes
19+
- name: Download k9s
20+
ansible.builtin.get_url:
21+
url: https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz
22+
dest: /tmp/k9s/k9s_Linux_amd64.tar.gz
23+
owner: root
24+
group: root
25+
mode: "744"
1726

18-
- name: Add k9s to root path
19-
ansible.builtin.copy:
20-
src: /root/k9s-temp/k9s
21-
dest: /usr/bin/k9s
22-
mode: u+rwx
23-
remote_src: yes
27+
- name: Unpack k9s binary
28+
ansible.builtin.unarchive:
29+
src: /tmp/k9s/k9s_Linux_amd64.tar.gz
30+
dest: /tmp/k9s
31+
remote_src: yes
2432

25-
- name: Add k3s kubeconfig as environment variable
26-
ansible.builtin.lineinfile:
27-
path: /etc/environment
28-
line: "KUBECONFIG=/etc/rancher/k3s/k3s.yaml"
33+
- name: Add k9s to root path
34+
ansible.builtin.copy:
35+
src: /tmp/k9s/k9s
36+
dest: /usr/bin/k9s
37+
mode: u+rwx
38+
remote_src: yes
2939

30-
- name: Cleanup k9s install directory
31-
ansible.builtin.file:
32-
path: /root/k9s-temp
33-
state: absent
40+
- name: Cleanup k9s install directory
41+
ansible.builtin.file:
42+
path: /tmp/k9s
43+
state: absent
44+
when: not result.stat.exists

environments/common/inventory/groups

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ freeipa_client
138138

139139
[k3s]
140140
# Hosts to run k3s server/agent
141+
142+
[k9s]
143+
# Hosts to install k9s on

environments/common/layouts/everything

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ cluster
8686
[k3s:children]
8787
# Hosts to run k3s server/agent
8888
openhpc
89+
90+
[k9s:children]
91+
control

0 commit comments

Comments
 (0)