Skip to content

Commit 7a0833d

Browse files
committed
Add var to opt-out of rke2 service restarts
1 parent 457b145 commit 7a0833d

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

defaults/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,8 @@ rke2_debug: false
284284

285285
# The value for the node-name configuration item
286286
rke2_node_name: "{{ inventory_hostname }}"
287+
288+
289+
# Allow the role to restart rke2 services as needed. Set to false if this will
290+
# be accomplished outside the role.
291+
rke2_restart_allowed: true

tasks/main.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,27 @@
5454
- active_server is defined
5555
- groups[rke2_cluster_group_name] | length | int >= 2
5656

57-
- name: Rolling cordon and drain restart when version changes
58-
ansible.builtin.include_tasks: rolling_restart.yml
59-
with_items: "{{ groups[rke2_cluster_group_name] }}"
60-
loop_control:
61-
loop_var: _host_item
57+
- name: "{{ _loop_name }}"
58+
ansible.builtin.include_tasks: rolling_loop.yml
59+
vars:
60+
_loop_name: Rolling cordon and drain restart when version changes
61+
_loop_over_tasks: rolling_restart.yml
6262
when:
63-
- hostvars[_host_item].inventory_hostname == inventory_hostname
63+
- rke2_restart_allowed
64+
- rke2_restart_needed
6465
- installed_version != "not installed"
6566
- rke2_version != running_version
6667

6768
- name: Flush handlers
6869
ansible.builtin.meta: flush_handlers
6970

70-
- name: Rolling restart when config files change
71-
ansible.builtin.include_tasks: change_config.yml
72-
with_items: "{{ groups[rke2_cluster_group_name] }}"
73-
loop_control:
74-
loop_var: _host_item
71+
- name: "{{ _loop_name }}"
72+
ansible.builtin.include_tasks: rolling_loop.yml
73+
vars:
74+
_loop_name: Rolling restart when config files change
75+
_loop_over_tasks: change_config_loop.yml
7576
when:
76-
- hostvars[_host_item].inventory_hostname == inventory_hostname
77+
- rke2_restart_allowed
7778
- rke2_restart_needed
7879

7980
- name: Final steps

tasks/rolling_loop.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Isolating this loop to a file reduces log spam and resource utilization
2+
# when restarts are not required.
3+
- name: "{{ _loop_name }} {{ hostvars[_host_item].inventory_hostname }}"
4+
ansible.builtin.include_tasks: "{{ _loop_over_tasks }}"
5+
with_items: "{{ groups[rke2_cluster_group_name] }}"
6+
loop_control:
7+
loop_var: _host_item
8+
when: hostvars[_host_item].inventory_hostname == inventory_hostname

0 commit comments

Comments
 (0)