Skip to content

Commit 101bb0f

Browse files
Merge pull request #270 from jLemmings/fix/fix-partition-rke2
Fix RKE2 binary path check
2 parents e32888f + 08a04f1 commit 101bb0f

File tree

3 files changed

+128
-132
lines changed

3 files changed

+128
-132
lines changed

tasks/cis.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: Create etcd group
43
ansible.builtin.group:
54
name: etcd
@@ -13,15 +12,9 @@
1312
comment: etcd user
1413
state: present
1514

16-
- name: Check if separate partition
17-
ansible.builtin.command: grep '/usr/local ' /proc/mounts
18-
changed_when: false
19-
register: partition_result
20-
failed_when: partition_result.rc >= 2
21-
2215
- name: Copy systemctl config file for kernel hardening
2316
ansible.builtin.copy:
24-
src: "{{ '/usr/local/share/rke2/rke2-cis-sysctl.conf' if (usr_local.stat.writeable) and (partition_result.rc == 1) else '/opt/rke2/share/rke2/rke2-cis-sysctl.conf' }}"
17+
src: "{{ '/usr/local/share/rke2/rke2-cis-sysctl.conf' if (usr_local.stat.writeable) or (partition_result.rc == 1) else '/opt/rke2/share/rke2/rke2-cis-sysctl.conf' }}"
2518
dest: /etc/sysctl.d/60-rke2-cis.conf
2619
mode: 0600
2720
remote_src: true

tasks/first_server.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: Create the RKE2 config dir
43
ansible.builtin.file:
54
state: directory
@@ -118,15 +117,15 @@
118117
changed_when: false
119118
register: node_status
120119
until:
121-
- '"kubelet has sufficient memory available" in node_status.stdout_lines'
122-
- '"kubelet has no disk pressure" in node_status.stdout_lines'
123-
- '"kubelet has sufficient PID available" in node_status.stdout_lines'
124-
- ('"cni plugin not initialized" in node_status.stdout' or '"kubelet is posting ready status." in node_status.stdout')
120+
- '"kubelet has sufficient memory available" in node_status.stdout_lines'
121+
- '"kubelet has no disk pressure" in node_status.stdout_lines'
122+
- '"kubelet has sufficient PID available" in node_status.stdout_lines'
123+
- ('"cni plugin not initialized" in node_status.stdout' or '"kubelet is posting ready status." in node_status.stdout')
125124
retries: 100
126125
delay: 15
127126
when:
128-
- not ansible_check_mode
129-
- rke2_cni == 'none'
127+
- not ansible_check_mode
128+
- rke2_cni == 'none'
130129

131130
- name: Wait for the first server be ready - with CNI
132131
ansible.builtin.shell: |
@@ -136,13 +135,12 @@
136135
executable: /bin/bash
137136
changed_when: false
138137
register: first_server
139-
until:
140-
'" Ready " in first_server.stdout'
138+
until: '" Ready " in first_server.stdout'
141139
retries: 40
142140
delay: 15
143141
when:
144-
- not ansible_check_mode
145-
- rke2_cni != 'none'
142+
- not ansible_check_mode
143+
- rke2_cni != 'none'
146144

147145
- name: Restore etcd
148146
when: do_etcd_restore is defined or do_etcd_restore_from_s3 is defined
@@ -162,7 +160,7 @@
162160
run_once: true
163161
register: node_names
164162

165-
- name: remove old <node>.node-password.rke2 secrets
163+
- name: Remove old <node>.node-password.rke2 secrets
166164
ansible.builtin.shell: |
167165
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \
168166
delete secret {{ item }}.node-password.rke2 -n kube-system 2>&1 || true
@@ -171,7 +169,7 @@
171169
with_items: "{{ registered_node_names.stdout_lines | difference(node_names) }}"
172170
changed_when: false
173171

174-
- name: remove old nodes
172+
- name: Remove old nodes
175173
ansible.builtin.shell: |
176174
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \
177175
delete node {{ item }} 2>&1 || true

tasks/rke2.yml

Lines changed: 116 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: Download RKE2 installation script
43
ansible.builtin.get_url:
54
url: "{{ rke2_install_bash_url }}"
@@ -31,59 +30,59 @@
3130
- rke2_airgap_mode
3231
- rke2_airgap_implementation == 'download'
3332
block:
34-
- name: Download sha256 checksum file
35-
ansible.builtin.get_url:
36-
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
37-
dest: "{{ rke2_artifact_path }}/sha256sum-{{ rke2_architecture }}.txt"
38-
force: yes
39-
mode: 0640
40-
timeout: 30
41-
- name: Download RKE2 artifacts and compare with checksums
42-
ansible.builtin.get_url:
43-
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/{{ item }}"
44-
dest: "{{ rke2_artifact_path }}/{{ item }}"
45-
mode: 0640
46-
checksum: "sha256:{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
47-
timeout: 30
48-
with_items: "{{ rke2_artifact | reject('search', 'sha256sum') | list }}"
33+
- name: Download sha256 checksum file
34+
ansible.builtin.get_url:
35+
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
36+
dest: "{{ rke2_artifact_path }}/sha256sum-{{ rke2_architecture }}.txt"
37+
force: yes
38+
mode: 0640
39+
timeout: 30
40+
- name: Download RKE2 artifacts and compare with checksums
41+
ansible.builtin.get_url:
42+
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/{{ item }}"
43+
dest: "{{ rke2_artifact_path }}/{{ item }}"
44+
mode: 0640
45+
checksum: "sha256:{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
46+
timeout: 30
47+
with_items: "{{ rke2_artifact | reject('search', 'sha256sum') | list }}"
4948
rescue:
50-
- name: "Remote downloading failed: Downloading locally and pushing to remote hosts"
51-
ansible.builtin.pause: # Slight delay to make sure you know it's gonna happen and have time to cancel
52-
seconds: 7
53-
- name: "Create {{ rke2_airgap_copy_sourcepath }}"
54-
delegate_to: localhost
55-
run_once: true
56-
ansible.builtin.file:
57-
path: "{{ rke2_airgap_copy_sourcepath }}"
58-
state: directory
59-
- name: Download RKE2 checksum locally
60-
delegate_to: localhost
61-
run_once: true
62-
register: checksum_file
63-
ansible.builtin.get_url:
64-
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
65-
dest: "{{ rke2_airgap_copy_sourcepath }}/"
66-
force: yes
67-
mode: 0640
68-
timeout: 30
69-
- name: Downloading RKE2 artifacts locally
70-
delegate_to: localhost
71-
run_once: true
72-
ansible.builtin.get_url:
73-
force: yes
74-
url: "{{ item }}"
75-
dest: "{{ rke2_airgap_copy_sourcepath }}/"
76-
with_items: "{{ [rke2_artifact_url+'/'+rke2_version+'/'] | product(rke2_artifact) | map('join') | list + [rke2_install_bash_url] }}"
77-
- name: Copy local RKE2 files to remote hosts
78-
ansible.builtin.copy:
79-
src: "{{ rke2_airgap_copy_sourcepath }}/{{ item }}"
80-
dest: "{{ rke2_artifact_path }}/{{ item }}"
81-
mode: 0640
82-
with_items: "{{ rke2_artifacts + ['rke2.sh'] }}"
83-
- name: Set RKE2 install script permissions
84-
ansible.builtin.file:
85-
path: "{{ rke2_artifact_path }}/rke2.sh"
86-
mode: 0750
49+
- name: "Remote downloading failed: Downloading locally and pushing to remote hosts"
50+
ansible.builtin.pause: # Slight delay to make sure you know it's gonna happen and have time to cancel
51+
seconds: 7
52+
- name: "Create {{ rke2_airgap_copy_sourcepath }}"
53+
delegate_to: localhost
54+
run_once: true
55+
ansible.builtin.file:
56+
path: "{{ rke2_airgap_copy_sourcepath }}"
57+
state: directory
58+
- name: Download RKE2 checksum locally
59+
delegate_to: localhost
60+
run_once: true
61+
register: checksum_file
62+
ansible.builtin.get_url:
63+
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
64+
dest: "{{ rke2_airgap_copy_sourcepath }}/"
65+
force: yes
66+
mode: 0640
67+
timeout: 30
68+
- name: Downloading RKE2 artifacts locally
69+
delegate_to: localhost
70+
run_once: true
71+
ansible.builtin.get_url:
72+
force: yes
73+
url: "{{ item }}"
74+
dest: "{{ rke2_airgap_copy_sourcepath }}/"
75+
with_items: "{{ [rke2_artifact_url+'/'+rke2_version+'/'] | product(rke2_artifact) | map('join') | list + [rke2_install_bash_url] }}"
76+
- name: Copy local RKE2 files to remote hosts
77+
ansible.builtin.copy:
78+
src: "{{ rke2_airgap_copy_sourcepath }}/{{ item }}"
79+
dest: "{{ rke2_artifact_path }}/{{ item }}"
80+
mode: 0640
81+
with_items: "{{ rke2_artifacts + ['rke2.sh'] }}"
82+
- name: Set RKE2 install script permissions
83+
ansible.builtin.file:
84+
path: "{{ rke2_artifact_path }}/rke2.sh"
85+
mode: 0750
8786

8887
- name: Copy local RKE2 artifacts
8988
ansible.builtin.copy:
@@ -102,18 +101,18 @@
102101
- ( rke2_airgap_copy_additional_tarballs | length > 0 )
103102
- rke2_airgap_implementation != 'exists'
104103
block:
105-
- name: Create additional images tarballs folder
106-
ansible.builtin.file:
107-
path: "{{ rke2_tarball_images_path }}"
108-
state: directory
109-
mode: 0700
110-
- name: Copy additional tarball images RKE2 components
111-
ansible.builtin.copy:
112-
src: "{{ rke2_airgap_copy_sourcepath }}/{{ item }}"
113-
dest: "{{ rke2_tarball_images_path }}/{{ item }}"
114-
mode: 0640
115-
force: yes
116-
with_items: "{{ rke2_airgap_copy_additional_tarballs }}"
104+
- name: Create additional images tarballs folder
105+
ansible.builtin.file:
106+
path: "{{ rke2_tarball_images_path }}"
107+
state: directory
108+
mode: 0700
109+
- name: Copy additional tarball images RKE2 components
110+
ansible.builtin.copy:
111+
src: "{{ rke2_airgap_copy_sourcepath }}/{{ item }}"
112+
dest: "{{ rke2_tarball_images_path }}/{{ item }}"
113+
mode: 0644
114+
force: yes
115+
with_items: "{{ rke2_airgap_copy_additional_tarballs }}"
117116

118117
- name: Airgap mode - ensure artifacts exist and have acceptable permissions # only modifies permissions if they are overprivileged
119118
when:
@@ -123,7 +122,7 @@
123122
- name: Register artifacts
124123
ansible.builtin.stat:
125124
path: "{{ rke2_artifact_path }}/{{ item }}"
126-
with_items: "{{ rke2_artifact }}"
125+
with_items: "{{ rke2_artifact }}"
127126
register: artifacts
128127
- name: Register install script
129128
ansible.builtin.stat:
@@ -158,9 +157,15 @@
158157
path: /usr/local
159158
register: usr_local
160159

160+
- name: Check if separate partition
161+
ansible.builtin.command: grep '/usr/local ' /proc/mounts
162+
changed_when: false
163+
register: partition_result
164+
failed_when: partition_result.rc >= 2
165+
161166
- name: Set RKE2 bin path
162167
ansible.builtin.set_fact:
163-
rke2_bin_path: "{{ '/usr/local/bin/rke2' if usr_local.stat.writeable == True else ' /opt/rke2/bin/rke2' }}"
168+
rke2_bin_path: "{{ '/usr/local/bin/rke2' if (usr_local.stat.writeable) or (partition_result.rc == 1) else '/opt/rke2/bin/rke2' }}"
164169

165170
- name: Check RKE2 version
166171
ansible.builtin.shell: |
@@ -206,25 +211,25 @@
206211
- name: Run RKE2 install script
207212
when: rke2_version != installed_version
208213
block:
209-
- name: Run the script with airgap variables
210-
ansible.builtin.command:
211-
cmd: "{{ rke2_install_script_dir }}/rke2.sh"
212-
environment:
213-
INSTALL_RKE2_ARTIFACT_PATH: "{{ rke2_artifact_path }}"
214-
INSTALL_RKE2_AGENT_IMAGES_DIR: "{{ rke2_data_path }}/agent/images"
215-
INSTALL_RKE2_METHOD: "{{ rke2_method }}"
216-
changed_when: false
217-
when: rke2_airgap_mode
218-
- name: Run RKE2 script without airgap variables
219-
ansible.builtin.command:
220-
cmd: "{{ rke2_install_script_dir }}/rke2.sh"
221-
environment:
222-
INSTALL_RKE2_VERSION: "{{ rke2_version }}"
223-
INSTALL_RKE2_CHANNEL_URL: "{{ rke2_channel_url }}"
224-
INSTALL_RKE2_CHANNEL: "{{ rke2_channel }}"
225-
INSTALL_RKE2_METHOD: "{{ rke2_method }}"
226-
changed_when: false
227-
when: not ansible_check_mode and not rke2_airgap_mode
214+
- name: Run the script with airgap variables
215+
ansible.builtin.command:
216+
cmd: "{{ rke2_install_script_dir }}/rke2.sh"
217+
environment:
218+
INSTALL_RKE2_ARTIFACT_PATH: "{{ rke2_artifact_path }}"
219+
INSTALL_RKE2_AGENT_IMAGES_DIR: "{{ rke2_data_path }}/agent/images"
220+
INSTALL_RKE2_METHOD: "{{ rke2_method }}"
221+
changed_when: false
222+
when: rke2_airgap_mode
223+
- name: Run RKE2 script without airgap variables
224+
ansible.builtin.command:
225+
cmd: "{{ rke2_install_script_dir }}/rke2.sh"
226+
environment:
227+
INSTALL_RKE2_VERSION: "{{ rke2_version }}"
228+
INSTALL_RKE2_CHANNEL_URL: "{{ rke2_channel_url }}"
229+
INSTALL_RKE2_CHANNEL: "{{ rke2_channel }}"
230+
INSTALL_RKE2_METHOD: "{{ rke2_method }}"
231+
changed_when: false
232+
when: not ansible_check_mode and not rke2_airgap_mode
228233

229234
- name: Copy Custom Manifests
230235
ansible.builtin.template:
@@ -239,31 +244,31 @@
239244
- name: Create /server/manifests directory
240245
when: rke2_custom_manifests or rke2_static_pods
241246
block:
242-
- name: Create directory
243-
ansible.builtin.file:
244-
path: "{{ rke2_data_path }}/server/manifests"
245-
state: directory
246-
mode: 0755
247-
- name: Copy Custom Manifests
248-
ansible.builtin.template:
249-
src: "{{ item }}"
250-
dest: "{{ rke2_data_path }}/server/manifests/{{ item | basename | regex_replace('\\.j2$', '') }}"
251-
owner: root
252-
group: root
253-
mode: 0644
254-
with_fileglob: "{{ rke2_custom_manifests }}/*"
255-
when:
256-
- rke2_custom_manifests
257-
- inventory_hostname == groups[rke2_servers_group_name].0
258-
- name: Copy Static Pods
259-
ansible.builtin.copy:
260-
src: "{{ item }}"
261-
dest: "{{ rke2_data_path }}/agent/pod-manifests/{{ item | basename | regex_replace('\\.j2$', '') }}"
262-
owner: root
263-
group: root
264-
mode: 0644
265-
with_fileglob: "{{ rke2_static_pods }}/*"
266-
when: rke2_static_pods
247+
- name: Create directory
248+
ansible.builtin.file:
249+
path: "{{ rke2_data_path }}/server/manifests"
250+
state: directory
251+
mode: 0755
252+
- name: Copy Custom Manifests
253+
ansible.builtin.template:
254+
src: "{{ item }}"
255+
dest: "{{ rke2_data_path }}/server/manifests/{{ item | basename | regex_replace('\\.j2$', '') }}"
256+
owner: root
257+
group: root
258+
mode: 0644
259+
with_fileglob: "{{ rke2_custom_manifests }}/*"
260+
when:
261+
- rke2_custom_manifests
262+
- inventory_hostname == groups[rke2_servers_group_name].0
263+
- name: Copy Static Pods
264+
ansible.builtin.copy:
265+
src: "{{ item }}"
266+
dest: "{{ rke2_data_path }}/agent/pod-manifests/{{ item | basename | regex_replace('\\.j2$', '') }}"
267+
owner: root
268+
group: root
269+
mode: 0644
270+
with_fileglob: "{{ rke2_static_pods }}/*"
271+
when: rke2_static_pods
267272

268273
- name: Copy RKE2 environment file
269274
ansible.builtin.template:

0 commit comments

Comments
 (0)