mirror of
https://gitlab.durp.info/durfy/runbooks/ansible.git
synced 2026-05-07 08:00:29 -05:00
73 lines
No EOL
2.1 KiB
YAML
73 lines
No EOL
2.1 KiB
YAML
- name: Validate cluster selection and derive group names
|
|
hosts: localhost
|
|
gather_facts: false
|
|
vars:
|
|
cluster: "{{ cluster | default('') }}"
|
|
cluster_prefix: "{{ cluster | regex_replace('-cluster$', '') }}"
|
|
master_group: "{{ cluster_prefix }}-master"
|
|
node_group: "{{ cluster_prefix }}-node"
|
|
tasks:
|
|
- name: cluster must be provided
|
|
ansible.builtin.assert:
|
|
that:
|
|
- cluster | length > 0
|
|
fail_msg: "Missing required var 'cluster'. Example: -e cluster=dev-cluster"
|
|
|
|
- name: cluster must be a *-cluster group
|
|
ansible.builtin.assert:
|
|
that:
|
|
- cluster is match('.*-cluster$')
|
|
fail_msg: "cluster must end with '-cluster' (ex: dev-cluster). Got: {{ cluster }}"
|
|
|
|
- name: cluster group must exist in inventory
|
|
ansible.builtin.assert:
|
|
that:
|
|
- cluster in groups
|
|
fail_msg: "Cluster group '{{ cluster }}' not found in inventory."
|
|
|
|
- name: derived master/node groups must exist in inventory
|
|
ansible.builtin.assert:
|
|
that:
|
|
- master_group in groups
|
|
- node_group in groups
|
|
fail_msg: >-
|
|
Expected derived groups '{{ master_group }}' and '{{ node_group }}' to exist in inventory
|
|
for cluster '{{ cluster }}'.
|
|
|
|
- name: Load k3s shared variables
|
|
hosts: localhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Load vars from k3s/vars/main.yaml
|
|
ansible.builtin.include_vars:
|
|
file: "ansible/roles/k3s/vars/main.yaml"
|
|
|
|
- name: Install prerequisites on all nodes
|
|
hosts: "{{ cluster }}"
|
|
gather_facts: yes
|
|
become: yes
|
|
roles:
|
|
- base
|
|
- k3s/prereq
|
|
- k3s/download
|
|
|
|
- name: Install k3s on master nodes
|
|
hosts: "{{ (cluster | regex_replace('-cluster$', '')) ~ '-master' }}"
|
|
gather_facts: yes
|
|
become: yes
|
|
roles:
|
|
- k3s/master
|
|
|
|
- name: Install k3s on worker nodes
|
|
hosts: "{{ (cluster | regex_replace('-cluster$', '')) ~ '-node' }}"
|
|
gather_facts: yes
|
|
become: yes
|
|
roles:
|
|
- k3s/node
|
|
|
|
- name: Post Install for k3s
|
|
hosts: "{{ (cluster | regex_replace('-cluster$', '')) ~ '-master' }}"
|
|
gather_facts: yes
|
|
become: yes
|
|
roles:
|
|
- k3s/post |