Skip to content

Commit

Permalink
Add var to opt-out of rke2 service restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
glennpratt committed May 9, 2024
1 parent 457b145 commit 7a0833d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,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
25 changes: 13 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,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
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

0 comments on commit 7a0833d

Please sign in to comment.