Skip to content

Commit 2588ea0

Browse files
Merge pull request #349 from lablabs/feat/enhancements
- Option to schedule etcd backup - Download the rke2.yaml file after the first server is ready, not at the end of the playbook
2 parents f86a57c + cbedd40 commit 2588ea0

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ rke2_etcd_snapshot_file: ""
207207
# Etcd snapshot location
208208
rke2_etcd_snapshot_destination_dir: "{{ rke2_data_path }}/server/db/snapshots"
209209

210+
# (Optional) Etcd snapshot schedule
211+
# The schedule is in cron format, e.g. "0 */12 * * *"
212+
# rke2_etcd_snapshot_schedule: "0 */12 * * *"
213+
210214
# Etcd snapshot s3 options
211215
# Set either all these values or `rke2_etcd_snapshot_file` and `rke2_etcd_snapshot_source_dir`
212216

meta/argument_specs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ argument_specs:
315315
default: "{{ rke2_data_path }}/server/db/snapshots"
316316
description: "Etcd snapshot location"
317317

318+
rke2_etcd_snapshot_schedule:
319+
type: str
320+
default: "0 */6 * * *"
321+
description: "Etcd snapshot schedule in cron format"
322+
318323
rke2_etcd_snapshot_s3_options:
319324
type: dict
320325
required: false

tasks/download_kubeconfig.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: Download RKE2 kubeconfig to localhost
3+
ansible.builtin.fetch:
4+
src: /etc/rancher/rke2/rke2.yaml
5+
dest: "{{ rke2_download_kubeconf_path }}/{{ rke2_download_kubeconf_file_name }}"
6+
flat: yes
7+
when:
8+
- rke2_download_kubeconf | bool
9+
- inventory_hostname == groups[rke2_servers_group_name].0
10+
11+
- name: Replace loopback IP by master server IP
12+
ansible.builtin.replace:
13+
path: "{{ rke2_download_kubeconf_path }}/{{ rke2_download_kubeconf_file_name }}"
14+
mode: '0600'
15+
regexp: '127\.0\.0\.1|\[::1\]'
16+
replace: "{{ rke2_api_ip | default(hostvars[groups[rke2_servers_group_name].0].ansible_host) | ansible.utils.ipwrap }}"
17+
delegate_to: localhost
18+
become: false
19+
when:
20+
- not ansible_check_mode
21+
- rke2_download_kubeconf | bool
22+
- inventory_hostname == groups[rke2_servers_group_name].0

tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
- inventory_hostname == active_server or inventory_hostname == groups[rke2_servers_group_name].0
5959
- do_etcd_restore is defined or do_etcd_restore_from_s3 is defined
6060

61+
- name: Download kubeconfig to ansible localhost
62+
ansible.builtin.include_tasks: download_kubeconfig.yaml
63+
when:
64+
- rke2_download_kubeconf | bool
65+
- inventory_hostname == groups[rke2_servers_group_name].0
66+
6167
- name: Prepare and join remaining nodes of the cluster
6268
ansible.builtin.include_tasks: remaining_nodes.yml
6369
when:

tasks/summary.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
11
---
2-
3-
- name: Download RKE2 kubeconfig to localhost
4-
ansible.builtin.fetch:
5-
src: /etc/rancher/rke2/rke2.yaml
6-
dest: "{{ rke2_download_kubeconf_path }}/{{ rke2_download_kubeconf_file_name }}"
7-
flat: yes
8-
when:
9-
- rke2_download_kubeconf | bool
10-
- inventory_hostname == groups[rke2_servers_group_name].0
11-
12-
- name: Replace loopback IP by master server IP
13-
ansible.builtin.replace:
14-
path: "{{ rke2_download_kubeconf_path }}/{{ rke2_download_kubeconf_file_name }}"
15-
mode: '0600'
16-
regexp: '127\.0\.0\.1|\[::1\]'
17-
replace: "{{ rke2_api_ip | default(hostvars[groups[rke2_servers_group_name].0].ansible_host) | ansible.utils.ipwrap }}"
18-
delegate_to: localhost
19-
become: false
20-
when:
21-
- not ansible_check_mode
22-
- rke2_download_kubeconf | bool
23-
- inventory_hostname == groups[rke2_servers_group_name].0
24-
252
- name: Summary
263
when: inventory_hostname == groups[rke2_servers_group_name].0
274
block:

templates/config.yaml.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ node-label:
4444
{% endfor %}
4545
{% endif %}
4646
snapshotter: {{ rke2_snapshotter }}
47+
{% if rke2_etcd_snapshot_schedule is defined %}
48+
etcd-snapshot-schedule-cron: "{{ rke2_etcd_snapshot_schedule }}"
49+
{% endif %}
4750
node-name: {{ rke2_node_name }}
4851
{% if ( disable_kube_proxy | bool ) %}
4952
disable-kube-proxy: true

0 commit comments

Comments
 (0)