|
10 | 10 | ansible.builtin.pause: |
11 | 11 | seconds: 5 |
12 | 12 | tasks: |
| 13 | + - name: Check if cluster is installed |
| 14 | + ansible.builtin.stat: |
| 15 | + path: /etc/rancher/k3s/config.yaml |
| 16 | + register: k3s_check_installed |
| 17 | + check_mode: false |
| 18 | + |
| 19 | + - name: Ignore manifests templates and urls if the cluster is already installed |
| 20 | + ansible.builtin.set_fact: |
| 21 | + k3s_server_manifests_templates: [] |
| 22 | + k3s_server_manifests_urls: [] |
| 23 | + when: k3s_check_installed.stat.exists |
| 24 | + |
13 | 25 | - name: Install Kubernetes |
14 | 26 | ansible.builtin.include_role: |
15 | 27 | name: xanmanning.k3s |
|
104 | 116 | namespace: kube-system |
105 | 117 | state: absent |
106 | 118 |
|
107 | | - # NOTE |
108 | 119 | # Cleaning up certain manifests from the /var/lib/rancher/k3s/server/manifests directory |
109 | 120 | # is needed because k3s has an awesome "feature" to always re-deploy them when the k3s |
110 | 121 | # service is restarted. Removing them does not uninstall the manifests from your cluster. |
111 | 122 |
|
112 | | - - name: Remove deployed manifest templates |
113 | | - ansible.builtin.file: |
114 | | - path: "{{ k3s_server_manifests_dir }}/{{ item | basename | regex_replace('\\.j2$', '') }}" |
115 | | - state: absent |
116 | | - loop: "{{ k3s_server_manifests_templates | default([]) }}" |
| 123 | + - name: Get a list of all custom manifest files |
| 124 | + ansible.builtin.find: |
| 125 | + paths: "{{ k3s_server_manifests_dir }}" |
| 126 | + file_type: file |
| 127 | + use_regex: true |
| 128 | + patterns: ["^custom-.*"] |
| 129 | + register: custom_manifest |
117 | 130 |
|
118 | | - - name: Remove deployed manifest urls |
| 131 | + - name: Delete all custom manifest files |
119 | 132 | ansible.builtin.file: |
120 | | - path: "{{ k3s_server_manifests_dir }}/{{ item.filename }}" |
| 133 | + path: "{{ item.path }}" |
121 | 134 | state: absent |
122 | | - loop: "{{ k3s_server_manifests_urls | default([]) }}" |
| 135 | + loop: "{{ custom_manifest.files }}" |
0 commit comments