Primary and secondary install tasks now check k3s_status.stat.exists so re-running the playbook is idempotent on already-provisioned nodes.
45 lines
1.2 KiB
YAML
45 lines
1.2 KiB
YAML
---
|
|
- name: Install dependencies
|
|
ansible.builtin.apt:
|
|
name: "{{ item }}"
|
|
state: present
|
|
update_cache: true
|
|
loop:
|
|
- qemu-guest-agent
|
|
- etcd-client
|
|
become: true
|
|
|
|
- name: See if k3s file exists
|
|
ansible.builtin.stat:
|
|
path: /usr/local/bin/k3s
|
|
register: k3s_status
|
|
|
|
- name: Install primary k3s server
|
|
include_tasks: primary_installation.yaml
|
|
when:
|
|
- inventory_hostname == groups['k3s_server'] | first
|
|
- not k3s_status.stat.exists
|
|
|
|
- name: Get token from primary k3s server
|
|
include_tasks: pull_token.yaml
|
|
|
|
- name: Install seconary k3s servers
|
|
include_tasks: secondary_installation.yaml
|
|
when:
|
|
- inventory_hostname != groups['k3s_server'] | first
|
|
- not k3s_status.stat.exists
|
|
|
|
- name: Set kubeconfig on localhost
|
|
include_tasks: create_kubeconfig.yaml
|
|
when: inventory_hostname == groups['k3s_server'] | first
|
|
|
|
- name: Persist control-plane NoSchedule taint in k3s config
|
|
ansible.builtin.blockinfile:
|
|
path: /etc/rancher/k3s/config.yaml
|
|
create: true
|
|
marker: "# {mark} ANSIBLE MANAGED control-plane taint"
|
|
block: |
|
|
node-taint:
|
|
- "node-role.kubernetes.io/control-plane:NoSchedule"
|
|
become: true
|