baseline/playbook.yml

62 lines
1.8 KiB
YAML
Raw Normal View History

# vim: set ft=yaml.ansible:
---
- name: Install k3s server
hosts: all
gather_facts: false
tags: k3s-server
vars:
k3s_version: v1.31.2+k3s1
tasks:
- name: Get k3s installed version
ansible.builtin.command: k3s --version
register: k3s_version_output
check_mode: false
changed_when: false
ignore_errors: true
- name: Set k3s installed version
when: k3s_version_output.rc == 0
ansible.builtin.set_fact:
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
- name: Download and install/update k3s
when: (k3s_version_output.rc != 0) or (installed_k3s_version != k3s_version)
block:
- name: Download K3s install script
ansible.builtin.get_url:
url: https://get.k3s.io
dest: /usr/local/bin/k3s_install.sh
mode: "755"
- name: Install k3s server
ansible.builtin.command: "k3s_install.sh"
environment:
K3S_NODE_NAME: "{{ inventory_hostname }}"
INSTALL_K3S_CHANNEL: "{{ k3s_version }}"
INSTALL_K3S_EXEC: "--disable=traefik --tls-san {{ inventory_hostname }}"
changed_when: false
- name: Start and enable k3s server
ansible.builtin.service:
name: k3s.service
state: started
enabled: true
- name: Add restart cronjob
ansible.builtin.cron:
name: "restart k3s (and regenerate certs if necessary)"
special_time: monthly
job: "systemctl restart k3s"
- name: Deploy ArgoCD
hosts: all
gather_facts: false
tags: baseline
tasks:
- name: Copy manifest
ansible.builtin.copy:
src: argocd-bootstrap/
dest: /var/lib/rancher/k3s/server/manifests/argocd-bootstrap/
mode: "0755"