-
Notifications
You must be signed in to change notification settings - Fork 131
/
rke2.yml
138 lines (123 loc) · 4.61 KB
/
rke2.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
- name: Download RKE2 installation script
ansible.builtin.get_url:
url: "{{ rke2_install_bash_url }}"
dest: "{{ rke2_install_script_dir }}/rke2.sh"
mode: 0700
when: (not rke2_airgap_mode) or rke2_airgap_implementation == 'download'
- name: Copy local RKE2 installation script
ansible.builtin.copy:
src: "{{ rke2_airgap_copy_sourcepath }}/rke2.sh"
dest: "{{ rke2_install_script_dir }}/rke2.sh"
mode: 0700
force: yes
when: rke2_airgap_mode and rke2_airgap_implementation == 'copy'
- name: Create RKE2 artifacts folder
ansible.builtin.file:
path: "{{ rke2_artifact_path }}"
state: directory
mode: 0700
when: rke2_airgap_mode
- name: Download RKE2 checksum and artifacts
when: rke2_airgap_mode and rke2_airgap_implementation == 'download'
block:
- name: Download sha256 checksum file
ansible.builtin.get_url:
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
dest: "{{ rke2_artifact_path }}/sha256sum-{{ rke2_architecture }}.txt"
force: yes
mode: 0644
timeout: 30
- name: Download RKE2 artifacts and compare with checksums
ansible.builtin.get_url:
url: "{{ rke2_artifact_url }}/{{ rke2_version }}/{{ item }}"
dest: "{{ rke2_artifact_path }}/{{ item }}"
mode: 0644
checksum: "sha256:{{ rke2_artifact_url }}/{{ rke2_version }}/sha256sum-{{ rke2_architecture }}.txt"
timeout: 30
with_items: "{{ rke2_artifact | reject('search', 'sha256sum') | list }}"
- name: Copy local RKE2 artifacts
ansible.builtin.copy:
src: "{{ rke2_airgap_copy_sourcepath }}/{{ item }}"
dest: "{{ rke2_artifact_path }}/{{ item }}"
mode: 0644
force: yes
with_items: "{{ rke2_artifact }}"
when: rke2_airgap_mode and rke2_airgap_implementation == 'copy'
- name: Airgap mode - additional images tarballs
when: rke2_airgap_mode and ( rke2_airgap_copy_additional_tarballs | length > 0 )
block:
- name: Create additional images tarballs folder
ansible.builtin.file:
path: "{{ rke2_tarball_images_path }}"
state: directory
mode: 0700
- name: Copy additional tarball images RKE2 components
ansible.builtin.copy:
src: "{{ rke2_airgap_copy_sourcepath }}/{{ item }}"
dest: "{{ rke2_tarball_images_path }}/{{ item }}"
mode: 0644
force: yes
with_items: "{{ rke2_airgap_copy_additional_tarballs }}"
- name: Populate service facts
ansible.builtin.service_facts:
- name: Get stats of the FS object
ansible.builtin.stat:
path: /usr/local
register: usr_local
- name: Set RKE2 bin path
ansible.builtin.set_fact:
rke2_bin_path: "{{ '/usr/local/bin/rke2' if usr_local.stat.writeable == True else ' /opt/rke2/bin/rke2' }}"
- name: Check RKE2 version
ansible.builtin.shell: |
set -o pipefail
{{ rke2_bin_path }} --version | grep -E "rke2 version" | awk '{print $3}'
args:
executable: /bin/bash
changed_when: false
register: installed_rke2_version
when: '"rke2-server.service" in ansible_facts.services'
- name: Run AirGap RKE2 script
ansible.builtin.command:
cmd: "{{ rke2_install_script_dir }}/rke2.sh"
environment:
INSTALL_RKE2_ARTIFACT_PATH: "{{ rke2_artifact_path }}"
INSTALL_RKE2_AGENT_IMAGES_DIR: "{{ rke2_data_path }}/agent/images"
when: (rke2_version != ( installed_rke2_version.stdout | default({})) and (rke2_airgap_mode))
or ((installed_rke2_version is not defined) and rke2_airgap_mode)
- name: Run RKE2 script
ansible.builtin.command:
cmd: "{{ rke2_install_script_dir }}/rke2.sh"
environment:
INSTALL_RKE2_VERSION: "{{ rke2_version }}"
INSTALL_RKE2_CHANNEL_URL: "{{ rke2_channel_url }}"
INSTALL_RKE2_CHANNEL: "{{ rke2_channel }}"
INSTALL_RKE2_METHOD: "{{ rke2_method }}"
when: (rke2_version != ( installed_rke2_version.stdout | default({})) and (not rke2_airgap_mode))
or ((installed_rke2_version is not defined) and (not rke2_airgap_mode))
- name: Copy Custom Manifests
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ rke2_data_path }}/server/manifests/"
owner: root
group: root
mode: 0644
with_items: "{{ rke2_custom_manifests }}"
when: rke2_custom_manifests
- name: Copy Static Pods
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ rke2_data_path }}/agent/pod-manifests/"
owner: root
group: root
mode: 0644
with_items: "{{ rke2_static_pods }}"
when: rke2_static_pods
- name: Copy RKE2 environment file
ansible.builtin.template:
src: rke2_environment.j2
dest: "/etc/default/rke2-{{ rke2_type }}"
owner: root
group: root
mode: 0644
when: rke2_environment_options is defined and rke2_environment_options|length > 0