From 292c726b071457dfbf547165a15044cafb8799c1 Mon Sep 17 00:00:00 2001 From: Xan Manning Date: Wed, 21 Oct 2020 17:22:41 +0100 Subject: [PATCH] Split out repeating tasks --- tasks/build/install-k3s-node.yml | 52 ++++++++++++++++++++++ tasks/build/install-k3s.yml | 75 ++------------------------------ 2 files changed, 56 insertions(+), 71 deletions(-) create mode 100644 tasks/build/install-k3s-node.yml diff --git a/tasks/build/install-k3s-node.yml b/tasks/build/install-k3s-node.yml new file mode 100644 index 0000000..0b190a0 --- /dev/null +++ b/tasks/build/install-k3s-node.yml @@ -0,0 +1,52 @@ +--- + +- name: Ensure k3s is linked into the installation destination + file: + src: "{{ k3s_install_dir }}/k3s-{{ k3s_release_version }}" + dest: "{{ k3s_install_dir }}/{{ item }}" + state: "{{ 'hard' if k3s_install_hard_links else 'link' }}" + force: "{{ k3s_install_hard_links }}" + mode: 0755 + loop: + - k3s + - kubectl + - crictl + - ctr + when: not ansible_check_mode + notify: + - restart k3s + become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}" + +- name: Ensure k3s config file exists + template: + src: config.yaml.j2 + dest: "{{ k3s_config_file }}" + mode: 0644 + notify: + - reload systemd + - restart k3s + become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}" + +- name: Ensure k3s service unit file is present + template: + src: k3s.service.j2 + dest: "{{ k3s_systemd_unit_directory }}/k3s.service" + mode: 0644 + notify: + - reload systemd + - restart k3s + become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}" + +- name: Ensure k3s killall script is present on all nodes + template: + src: k3s-killall.sh.j2 + dest: "/usr/local/bin/k3s-killall.sh" + mode: 0700 + become: "{{ k3s_become_for_usr_local_bin | ternary(true, false, k3s_become_for_all) }}" + +- name: Ensure k3s uninstall script is present on all nodes + template: + src: k3s-uninstall.sh.j2 + dest: "/usr/local/bin/k3s-uninstall.sh" + mode: 0700 + become: "{{ k3s_become_for_usr_local_bin | ternary(true, false, k3s_become_for_all) }}" diff --git a/tasks/build/install-k3s.yml b/tasks/build/install-k3s.yml index b129729..2c49646 100644 --- a/tasks/build/install-k3s.yml +++ b/tasks/build/install-k3s.yml @@ -1,23 +1,5 @@ --- -- name: Ensure k3s is linked into the installation destination on the contol plane - file: - src: "{{ k3s_install_dir }}/k3s-{{ k3s_release_version }}" - dest: "{{ k3s_install_dir }}/{{ item }}" - state: "{{ 'hard' if k3s_install_hard_links else 'link' }}" - force: "{{ k3s_install_hard_links }}" - mode: 0755 - loop: - - k3s - - kubectl - - crictl - - ctr - when: ((k3s_control_node and k3s_controller_count | length == 1) - or (k3s_primary_control_node and k3s_controller_count | length > 1)) and not ansible_check_mode - notify: - - restart k3s - become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}" - - name: Ensure config directory exists file: path: "{{ k3s_config_file | dirname }}" @@ -33,62 +15,13 @@ mode: 0755 become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}" -- name: Ensure k3s config file exists on control plane - template: - src: config.yaml.j2 - dest: "{{ k3s_config_file }}" - mode: 0644 - when: (k3s_control_node and k3s_controller_count | length == 1) - or (k3s_primary_control_node and k3s_controller_count | length > 1) - notify: - - reload systemd - - restart k3s - become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}" - -- name: Ensure k3s service unit file is present on control plane - template: - src: k3s.service.j2 - dest: "{{ k3s_systemd_unit_directory }}/k3s.service" - mode: 0644 - when: (k3s_control_node and k3s_controller_count | length == 1) - or (k3s_primary_control_node and k3s_controller_count | length > 1) - notify: - - reload systemd - - restart k3s - become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}" +- include_tasks: install-k3s-node.yml + when: ((k3s_control_node and k3s_controller_count | length == 1) + or (k3s_primary_control_node and k3s_controller_count | length > 1)) and not ansible_check_mode - meta: flush_handlers -- name: Ensure k3s killall script is present on all nodes - template: - src: k3s-killall.sh.j2 - dest: "/usr/local/bin/k3s-killall.sh" - mode: 0700 - become: "{{ k3s_become_for_usr_local_bin | ternary(true, false, k3s_become_for_all) }}" - -- name: Ensure k3s uninstall script is present on all nodes - template: - src: k3s-uninstall.sh.j2 - dest: "/usr/local/bin/k3s-uninstall.sh" - mode: 0700 - become: "{{ k3s_become_for_usr_local_bin | ternary(true, false, k3s_become_for_all) }}" - -- name: Ensure k3s is linked into the installation destinations across all nodes - file: - src: "{{ k3s_install_dir }}/k3s-{{ k3s_release_version }}" - dest: "{{ k3s_install_dir }}/{{ item }}" - state: "{{ 'hard' if k3s_install_hard_links else 'link' }}" - force: "{{ k3s_install_hard_links }}" - mode: 0755 - notify: - - restart k3s - loop: - - k3s - - kubectl - - crictl - - ctr - when: not ansible_check_mode - become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}" +- include_tasks: install-k3s-node.yml - name: Ensure k3s control plane is started systemd: