Skip to content

Commit 902b996

Browse files
committed
Add var to opt-out of rke2 service restarts
1 parent 8ead9d0 commit 902b996

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,8 @@ rke2_debug: false
291291

292292
# The value for the node-name configuration item
293293
rke2_node_name: "{{ inventory_hostname }}"
294+
295+
296+
# Allow the role to restart rke2 services as needed. Set to false if this will
297+
# be accomplished outside the role.
298+
rke2_restart_allowed: true

tasks/main.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,27 @@
5959
- active_server is defined
6060
- groups[rke2_cluster_group_name] | length | int >= 2
6161

62-
- name: Rolling cordon and drain restart when version changes
63-
ansible.builtin.include_tasks: rolling_restart.yml
64-
with_items: "{{ groups[rke2_cluster_group_name] }}"
65-
loop_control:
66-
loop_var: _host_item
62+
- name: "{{ _loop_name }}"
63+
ansible.builtin.include_tasks: rolling_loop.yml
64+
vars:
65+
_loop_name: Rolling cordon and drain restart when version changes
66+
_loop_over_tasks: rolling_restart.yml
6767
when:
68-
- hostvars[_host_item].inventory_hostname == inventory_hostname
68+
- rke2_restart_allowed
69+
- rke2_restart_needed
6970
- installed_version != "not installed"
7071
- rke2_version != running_version
7172

7273
- name: Flush handlers
7374
ansible.builtin.meta: flush_handlers
7475

75-
- name: Rolling restart when config files change
76-
ansible.builtin.include_tasks: change_config.yml
77-
with_items: "{{ groups[rke2_cluster_group_name] }}"
78-
loop_control:
79-
loop_var: _host_item
76+
- name: "{{ _loop_name }}"
77+
ansible.builtin.include_tasks: rolling_loop.yml
78+
vars:
79+
_loop_name: Rolling restart when config files change
80+
_loop_over_tasks: change_config_loop.yml
8081
when:
81-
- hostvars[_host_item].inventory_hostname == inventory_hostname
82+
- rke2_restart_allowed
8283
- rke2_restart_needed
8384

8485
- name: Final steps

tasks/rolling_loop.yml

Lines changed: 8 additions & 0 deletions
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)