-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dancard32/k3s-ha
K3s Ansible Automation
- Loading branch information
Showing
33 changed files
with
542 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode | ||
.secrets/ | ||
.env | ||
.env | ||
.ansible/inventory.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
collections: | ||
- name: ansible.utils | ||
- name: community.general | ||
- name: ansible.posix | ||
- name: kubernetes.core | ||
- name: community.Mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
k3s_version: v1.22.3+k3s1 | ||
ansible_user: "dcard" | ||
systemd_dir: /etc/systemd/system | ||
server_ip: "{{ hostvars[groups['servers'][0]]['ansible_host'] | default(groups['servers'][0]) }}" | ||
|
||
# k3s_token is required servers can talk together securely | ||
# this token should be alpha numeric only | ||
k3s_token: "eyJhbGciOiJSUzI1NiIsImtpZCI6IlVNZG44MXQxZnRib28tS0RHMTYyZ1dqTTlnQWE2QjVyMGd4VDZCSkdDRUEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tY2w3a2MiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImU4ODFmNDVlLTMxNGUtNGUyOC04YmYxLWNiYjI5ODFlNWM2MyIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.ZgFB3OUfxoo1l_7DUBmyIAjyysVrkD7DdnbP_DDBxJ_EqDNnuAkazyv8saYU6SCT621OgCJPH-h2l1O-dwodpUSNHdjSC0pGt2r7hg9pCSC3g-8Y8xeIYwaOh50fWJv-Zqk_1qIvY25jj-UPeMZel-xEG8IPRlpZFi6WdoXwzEMKzgUqatzfcH4Tl_eZGbRuacYpJswiJSjd3Ut626LER0HEB7NtlQtMZOjTTWORorrxdbmIYAxufBxIAAYX_ivTxPTMt_QMu7aqh2qYvrO7IGRHte0ZCWCAA_WtsqNET69W_J0ay2GrkhwLcJk7L4C9tLqq2yQn_9Rtg-RwprsmxQ" | ||
|
||
extra_server_args: "" | ||
extra_agent_args: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
|
||
- name: Install pre-requisites on Bare Metal | ||
hosts: localhost | ||
become: true | ||
connection: local | ||
roles: | ||
- installs-apt | ||
- installs-snap | ||
- installs-pip | ||
- metal | ||
|
||
- name: Install Docker on Bare Metal and Cluster | ||
hosts: k3s_cluster, localhost | ||
become: true | ||
roles: | ||
- docker-install | ||
|
||
- name: Gerneate Docker container bind mounts | ||
hosts: localhost | ||
become: true | ||
roles: | ||
- docker-mkdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[proxmox] | ||
192.168.122.20 ansible_ssh_user=root ansible_ssh_pass= | ||
|
||
# Change this list to the ip addresses of the servers | ||
[servers] | ||
192.168.10.115 ansible_ssh_user=dcard ansible_ssh_pass=asdf | ||
192.168.10.116 ansible_ssh_user=dcard ansible_ssh_pass=asdf | ||
|
||
# Change this list to the ip addresses of the agents | ||
[nodes] | ||
192.168.10.117 ansible_ssh_user=dcard ansible_ssh_pass=asdf | ||
192.168.10.118 ansible_ssh_user=dcard ansible_ssh_pass=asdf | ||
192.168.10.119 ansible_ssh_user=dcard ansible_ssh_pass=asdf | ||
|
||
|
||
# This group helps to better manage the cluster | ||
[k3s_cluster:children] | ||
servers | ||
nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
|
||
- name: Install k3s | ||
hosts: k3s_cluster | ||
become: true | ||
roles: | ||
- k3s-download | ||
- k3s-install | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- name: Reset k3s | ||
hosts: k3s_cluster | ||
become: true | ||
roles: | ||
- k3s-reset | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
|
||
- name: Clone Proxmox VM | ||
hosts: proxmox | ||
vars_prompt: | ||
- name: password | ||
prompt: What is your proxmox password? | ||
|
||
- name: vm_names_csv | ||
prompt: "Please specify the server names, separated by commas (NO SPACES)" | ||
private: false | ||
tasks: | ||
- set_fact: | ||
vm_names: "{{ vm_names_csv.split(',') }}" | ||
|
||
- name: Clone VM | ||
proxmox_kvm: | ||
api_user: root@pam | ||
api_password: "{{ password }}" | ||
api_host: 192.168.122.20 | ||
clone: ubuntu-server | ||
name: "{{ item }}" | ||
node: proxmox | ||
storage: local-lvm | ||
format: qcow2 | ||
timeout: 500 | ||
loop: "{{ vm_names }}" | ||
|
||
|
||
- name: Pause for 5 seconds before starting | ||
ansible.builtin.pause: | ||
seconds: 3 | ||
|
||
- name: Start VM | ||
proxmox_kvm: | ||
api_user: root@pam | ||
api_password: "{{ password }}" | ||
api_host: 192.168.122.20 | ||
name: "{{ item }}" | ||
node: proxmox | ||
state: started | ||
loop: "{{ vm_names }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
|
||
- name: Delete Proxmox VM's | ||
hosts: proxmox | ||
vars_prompt: | ||
- name: password | ||
prompt: What is your proxmox password? | ||
|
||
- name: vm_names_csv | ||
prompt: "Please specify the server names, separated by commas (NO SPACES)" | ||
private: false | ||
tasks: | ||
- set_fact: | ||
vm_names: "{{ vm_names_csv.split(',') }}" | ||
|
||
- name: Stop VM with force | ||
proxmox_kvm: | ||
api_user : root@pam | ||
api_password: "{{ password }}" | ||
api_host : 192.168.122.20 | ||
name : "{{ item }}" | ||
node : proxmox | ||
state : stopped | ||
force : yes | ||
timeout: 50 | ||
loop: "{{ vm_names }}" | ||
|
||
- name: Remove VM | ||
proxmox_kvm: | ||
api_user : root@pam | ||
api_password: "{{ password }}" | ||
api_host : 192.168.122.20 | ||
name : "{{ item }}" | ||
node : proxmox | ||
state : absent | ||
loop: "{{ vm_names }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
|
||
- name: Docker - Create $HOME/appdata directory | ||
file: | ||
path: "~/appdata" | ||
state: directory | ||
mode: '777' | ||
become: false | ||
|
||
- name: Docker - Create service config directories | ||
file: | ||
path: "~/appdata/{{ item }}" | ||
state: directory | ||
mode: '777' | ||
become: false | ||
|
||
with_items: | ||
- heimdall/config | ||
- jellyfin/library | ||
- jellyfin/movies | ||
- jellyfin/tvseries | ||
- yacht/config | ||
- deluge/config | ||
- radarr/config | ||
- sonarr/config | ||
- pi-hole | ||
- pi-hole/dns-masq.d | ||
- homeassistant | ||
- portainer | ||
- guacamole | ||
- dashy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
|
||
# General Homelab Tools | ||
- name: (APT) Install General Tools | ||
become: true | ||
apt: | ||
name: "{{ item }}" | ||
with_items: | ||
- net-tools | ||
- lm-sensors # Used to monitor computer temperatures | ||
- powertop # `sudo powertop` displays metrics about computer usage | ||
- openssh-server # To allow remote SSH | ||
- sshpass | ||
- hardinfo # This is the linux equivalent to device manager - run hardinfo in terminal | ||
- ethtool # Used for network debugging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# python pip installs | ||
- name: (PIP) Install General Tools | ||
ansible.builtin.pip: | ||
name: | ||
- proxmoxer | ||
- netaddr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
|
||
# Snap installs | ||
- name: (SNAP) Install General Tools | ||
community.general.snap: | ||
name: | ||
- kompose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
|
||
- name: Download k3s binary x64 | ||
get_url: | ||
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s | ||
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt | ||
dest: /usr/local/bin/k3s | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: ansible_facts.architecture == "x86_64" | ||
|
||
- name: Download k3s binary arm64 | ||
get_url: | ||
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64 | ||
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm64.txt | ||
dest: /usr/local/bin/k3s | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: | ||
- ( ansible_facts.architecture is search("arm") and | ||
ansible_facts.userspace_bits == "64" ) or | ||
ansible_facts.architecture is search("aarch64") | ||
|
||
- name: Download k3s binary armhf | ||
get_url: | ||
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-armhf | ||
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm.txt | ||
dest: /usr/local/bin/k3s | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: | ||
- ansible_facts.architecture is search("arm") | ||
- ansible_facts.userspace_bits == "32" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
k3s_server_location: /var/lib/rancher/k3s | ||
pip_version: "23.1.*" | ||
pip_get_pip_version: "latest" | ||
pip_executable: "pip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- name: Install k3s on servers | ||
import_tasks: server.yml | ||
when: inventory_hostname in groups['servers'] | ||
|
||
- name: Install k3s on nodes | ||
import_tasks: node.yml | ||
when: inventory_hostname in groups['nodes'] |
Oops, something went wrong.