From 902b99643472f8ddcf70eed23d6901e1bd1c923e Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Wed, 8 May 2024 16:11:22 -0700 Subject: [PATCH 1/5] Add var to opt-out of rke2 service restarts --- defaults/main.yml | 5 +++++ tasks/main.yml | 25 +++++++++++++------------ tasks/rolling_loop.yml | 8 ++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 tasks/rolling_loop.yml diff --git a/defaults/main.yml b/defaults/main.yml index 93942c6..db079a5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -291,3 +291,8 @@ rke2_debug: false # The value for the node-name configuration item rke2_node_name: "{{ inventory_hostname }}" + + +# Allow the role to restart rke2 services as needed. Set to false if this will +# be accomplished outside the role. +rke2_restart_allowed: true diff --git a/tasks/main.yml b/tasks/main.yml index c1f00b7..c54c0a0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -59,26 +59,27 @@ - active_server is defined - groups[rke2_cluster_group_name] | length | int >= 2 -- name: Rolling cordon and drain restart when version changes - ansible.builtin.include_tasks: rolling_restart.yml - with_items: "{{ groups[rke2_cluster_group_name] }}" - loop_control: - loop_var: _host_item +- name: "{{ _loop_name }}" + ansible.builtin.include_tasks: rolling_loop.yml + vars: + _loop_name: Rolling cordon and drain restart when version changes + _loop_over_tasks: rolling_restart.yml when: - - hostvars[_host_item].inventory_hostname == inventory_hostname + - rke2_restart_allowed + - rke2_restart_needed - installed_version != "not installed" - rke2_version != running_version - name: Flush handlers ansible.builtin.meta: flush_handlers -- name: Rolling restart when config files change - ansible.builtin.include_tasks: change_config.yml - with_items: "{{ groups[rke2_cluster_group_name] }}" - loop_control: - loop_var: _host_item +- name: "{{ _loop_name }}" + ansible.builtin.include_tasks: rolling_loop.yml + vars: + _loop_name: Rolling restart when config files change + _loop_over_tasks: change_config_loop.yml when: - - hostvars[_host_item].inventory_hostname == inventory_hostname + - rke2_restart_allowed - rke2_restart_needed - name: Final steps diff --git a/tasks/rolling_loop.yml b/tasks/rolling_loop.yml new file mode 100644 index 0000000..4753534 --- /dev/null +++ b/tasks/rolling_loop.yml @@ -0,0 +1,8 @@ +# Isolating this loop to a file reduces log spam and resource utilization +# when restarts are not required. +- name: "{{ _loop_name }} {{ hostvars[_host_item].inventory_hostname }}" + ansible.builtin.include_tasks: "{{ _loop_over_tasks }}" + with_items: "{{ groups[rke2_cluster_group_name] }}" + loop_control: + loop_var: _host_item + when: hostvars[_host_item].inventory_hostname == inventory_hostname From 167ea5a647917f84bf47deb7e22d97a34f4d5576 Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Thu, 9 May 2024 10:21:18 -0700 Subject: [PATCH 2/5] Remove redundant service fact gathering --- tasks/find_active_server.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tasks/find_active_server.yml b/tasks/find_active_server.yml index 60e3a45..5149279 100644 --- a/tasks/find_active_server.yml +++ b/tasks/find_active_server.yml @@ -1,8 +1,5 @@ --- -- name: Populate services facts - ansible.builtin.service_facts: - - name: Set the Active Server variable ansible.builtin.set_fact: active_server: "{{ inventory_hostname }}" From d63ef70b754f7a7dfe0493ff1f5b0fa71b6f39cf Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Tue, 28 May 2024 13:17:27 -0700 Subject: [PATCH 3/5] reuse rolling_restart --- tasks/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index c54c0a0..0f836e3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -77,7 +77,9 @@ ansible.builtin.include_tasks: rolling_loop.yml vars: _loop_name: Rolling restart when config files change - _loop_over_tasks: change_config_loop.yml + _loop_over_tasks: rolling_restart.yml + # drain not required for config change only + rke2_drain_node_during_upgrade: false when: - rke2_restart_allowed - rke2_restart_needed From c1c74fec14f348f3717d8dc365288dae7f873bc2 Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Fri, 31 May 2024 11:37:14 -0700 Subject: [PATCH 4/5] fix --- tasks/find_active_server.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/find_active_server.yml b/tasks/find_active_server.yml index 5149279..a481101 100644 --- a/tasks/find_active_server.yml +++ b/tasks/find_active_server.yml @@ -1,5 +1,10 @@ --- +- name: Populate services facts + ansible.builtin.service_facts: + # gathering service facts can be slow, only do so after install / upgrade + when: rke2_version != installed_version + - name: Set the Active Server variable ansible.builtin.set_fact: active_server: "{{ inventory_hostname }}" From 4572207735465c2e4f28e0ac57d8b2f79e063ff0 Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Fri, 31 May 2024 11:53:39 -0700 Subject: [PATCH 5/5] cleanup --- defaults/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index db079a5..8f8d1e2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -292,7 +292,6 @@ rke2_debug: false # The value for the node-name configuration item rke2_node_name: "{{ inventory_hostname }}" - # Allow the role to restart rke2 services as needed. Set to false if this will # be accomplished outside the role. rke2_restart_allowed: true