Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add var to opt-out of rke2 service restarts #215

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,7 @@ 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
2 changes: 2 additions & 0 deletions tasks/find_active_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- 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:
Expand Down
27 changes: 15 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,29 @@
- 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: rolling_restart.yml
# drain not required for config change only
rke2_drain_node_during_upgrade: false
when:
- hostvars[_host_item].inventory_hostname == inventory_hostname
- rke2_restart_allowed
- rke2_restart_needed

- name: Final steps
Expand Down
8 changes: 8 additions & 0 deletions tasks/rolling_loop.yml
Original file line number Diff line number Diff line change
@@ -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