adding ansible

This commit is contained in:
2026-07-17 21:12:47 -03:00
parent 7c2086009a
commit 2d29bddfcd
8 changed files with 155 additions and 0 deletions

4
ansible/.ansible-lint Normal file
View File

@@ -0,0 +1,4 @@
---
profile: basic
exclude_paths:
- collections/

13
ansible/.gitignore vendored Normal file
View File

@@ -0,0 +1,13 @@
# Encrypted secrets
group_vars/all/vault.yml
# Installed collections
collections/
# Ansible retry files
*.retry
# Local controller environment and test caches
.venv/
__pycache__/
.pytest_cache/

9
ansible/ansible.cfg Normal file
View File

@@ -0,0 +1,9 @@
[defaults]
inventory = inventory.yml
host_key_checking = True
retry_files_enabled = False
stdout_callback = default
result_format = yaml
collections_path = ./collections
roles_path = ./roles
interpreter_python = auto_silent

49
ansible/inventory.yml Normal file
View File

@@ -0,0 +1,49 @@
---
# Proxmox connection: local API access (the controller reaches the node directly).
# This is the "proxmox" group — not an SSH target, just connection params.
all:
children:
proxmox_nodes:
hosts:
otherside:
ansible_host: otherside.haven
ansible_connection: local # we call the Proxmox API, not SSH
astrid:
ansible_host: astrid.haven
ansible_connection: local # we call the Proxmox API, not SSH
k3s_cluster:
children:
grp_k3s_server: # group name == group_vars/grp_k3s_server.yml
hosts:
iris:
ansible_host: iris.haven
ansible_user: root
ansible_python_interpreter: /usr/bin/python3
grp_k3s_agent: # group name == group_vars/grp_k3s_agent.yml
hosts:
vega:
ansible_host: vega.haven
ansible_user: root
ansible_python_interpreter: /usr/bin/python3
nebula:
ansible_host: nebula.haven
ansible_user: root
ansible_python_interpreter: /usr/bin/python3
nexus:
ansible_host: nexus.haven
ansible_user: root
ansible_python_interpreter: /usr/bin/python3
lxcs:
children:
grp_docker_build: # group name == group_vars/grp_docker_build.yml
hosts:
docker_build:
ansible_host: docker-build.haven
ansible_user: root
ansible_python_interpreter: /usr/bin/python3
grp_redis: # group name == group_vars/grp_redis.yml
hosts:
redis:
ansible_host: redis.haven
ansible_user: root
ansible_python_interpreter: /usr/bin/python3

View File

@@ -0,0 +1,69 @@
## Updates k3s in the entire cluster
- name: Update k3s Control Plane
hosts: grp_k3s_server
serial: 1
gather_facts: false
become: true
tasks:
- name: Update k3s on control plane node
ansible.builtin.shell: >
sh <(curl -sfL https://get.k3s.io)
args:
executable: /bin/bash
register: k3s_update
- name: Print update output
ansible.builtin.debug:
var: k3s_update
- name: Update k3s Agents
hosts: grp_k3s_agent
serial: 1
gather_facts: false
become: true
tasks:
- name: Cordon agent node
ansible.builtin.command: kubectl cordon {{ inventory_hostname }}
delegate_to: "{{ groups['grp_k3s_server'][0] }}"
environment:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
ignore_errors: true
- name: Drain agent node
ansible.builtin.command: >
kubectl drain {{ inventory_hostname }}
--ignore-daemonsets
--delete-emptydir-data
--force
--timeout=60s
delegate_to: "{{ groups['grp_k3s_server'][0] }}"
environment:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
ignore_errors: true
- name: Kill k3s-agent process
ansible.builtin.shell: k3s-killall.sh
ignore_errors: true
- name: Update k3s on agent node
ansible.builtin.shell: >
sh <(curl -sfL https://get.k3s.io)
args:
executable: /bin/bash
register: k3s_update
- name: Restart k3s-agent service
ansible.builtin.systemd:
name: k3s-agent
state: restarted
- name: Print update output
ansible.builtin.debug:
var: k3s_update
- name: Uncordon agent node
ansible.builtin.command: kubectl uncordon {{ inventory_hostname }}
delegate_to: "{{ groups['grp_k3s_server'][0] }}"
environment:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
ignore_errors: true

View File

@@ -0,0 +1,2 @@
-r requirements-python.txt
ansible-lint==26.6.0

View File

@@ -0,0 +1,3 @@
ansible-core==2.21.2
proxmoxer==2.3.0
requests==2.34.2

6
ansible/requirements.yml Normal file
View File

@@ -0,0 +1,6 @@
---
collections:
- name: community.proxmox
version: "2.0.0"
- name: community.general
version: "13.2.0"