95 lines
2.7 KiB
YAML
95 lines
2.7 KiB
YAML
---
|
|
- name: Pre tasks
|
|
hosts: k3s_cluster
|
|
pre_tasks:
|
|
- name: Verify Ansible is version 2.11 or above. (If this fails you may need to update Ansible)
|
|
ansible.builtin.assert:
|
|
that: ansible_version.full is version_compare('2.11', '>=')
|
|
msg: >
|
|
"Ansible is out of date. See here for more info: https://docs.technotim.live/posts/ansible-automation/"
|
|
tasks:
|
|
- name: Disable multipathd for longhorn
|
|
become: true
|
|
service:
|
|
name: "{{ item }}"
|
|
state: stopped
|
|
enabled: false
|
|
loop:
|
|
- multipathd.service
|
|
- multipathd.socket
|
|
|
|
- name: Create LVM and mount it
|
|
hosts: lvm
|
|
become: true
|
|
vars:
|
|
pv_disks: "{{ lvm.pv_disks }}"
|
|
vg_name: "{{ lvm.vg_name }}"
|
|
lv_name: "{{ lvm.lv_name }}"
|
|
lv_size: "{{ lvm.lv_size }}"
|
|
fs_type: "{{ lvm.fs_type }}"
|
|
# Consider mounting directly at the /var/lib/longhorn in the future
|
|
mount_path: "{{ lvm.mount_path }}"
|
|
roles:
|
|
- lvm
|
|
|
|
- name: Prepare Proxmox cluster
|
|
hosts: proxmox
|
|
gather_facts: true
|
|
become: true
|
|
environment: "{{ proxy_env | default({}) }}"
|
|
roles:
|
|
- role: techno_tim.k3s_ansible.proxmox_lxc
|
|
when: proxmox_lxc_configure
|
|
|
|
- name: Prepare k3s nodes
|
|
hosts: k3s_cluster
|
|
gather_facts: true
|
|
environment: "{{ proxy_env | default({}) }}"
|
|
roles:
|
|
- role: techno_tim.k3s_ansible.lxc
|
|
become: true
|
|
when: proxmox_lxc_configure
|
|
- role: techno_tim.k3s_ansible.prereq
|
|
become: true
|
|
- role: techno_tim.k3s_ansible.download
|
|
become: true
|
|
- role: techno_tim.k3s_ansible.raspberrypi
|
|
become: true
|
|
- role: techno_tim.k3s_ansible.k3s_custom_registries
|
|
become: true
|
|
when: custom_registries
|
|
|
|
- name: Setup k3s servers
|
|
hosts: master
|
|
environment: "{{ proxy_env | default({}) }}"
|
|
roles:
|
|
- role: techno_tim.k3s_ansible.k3s_server
|
|
when: not (skip_setup_servers | default(false))
|
|
become: true
|
|
|
|
- name: Setup k3s agents
|
|
hosts: node
|
|
environment: "{{ proxy_env | default({}) }}"
|
|
roles:
|
|
- role: techno_tim.k3s_ansible.k3s_agent
|
|
when: not (skip_setup_agents | default(false))
|
|
become: true
|
|
|
|
- name: Configure k3s cluster
|
|
hosts: master
|
|
environment: "{{ proxy_env | default({}) }}"
|
|
roles:
|
|
- role: techno_tim.k3s_ansible.k3s_server_post
|
|
become: true
|
|
|
|
- name: Storing kubeconfig in the playbook directory
|
|
hosts: master
|
|
environment: "{{ proxy_env | default({}) }}"
|
|
tasks:
|
|
- name: Copying kubeconfig from {{ hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] }}
|
|
ansible.builtin.fetch:
|
|
src: "{{ ansible_user_dir }}/.kube/config"
|
|
dest: ./kubeconfig
|
|
flat: true
|
|
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|