|
1 | 1 | ---
|
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 |
6 | 7 |
|
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 |
11 | 18 |
|
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" |
17 | 26 |
|
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 |
24 | 32 |
|
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 |
29 | 39 |
|
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 |
0 commit comments