First commit

This commit is contained in:
2025-06-09 23:32:10 -04:00
commit 863aaeabc7
92 changed files with 2992 additions and 0 deletions

2
ansible/k3s/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.ansible
inventory.ini

View File

@@ -0,0 +1,51 @@
- name: Configurar disco adicional en las VMs
hosts: k3s_cluster
become: yes
collections:
- community.general
tasks:
- name: Verificar si el disco /dev/vdb existe
ansible.builtin.stat:
path: /dev/vdb
register: disk_check
- name: Crear particion de datos en disco /dev/vdb
community.general.parted:
device: /dev/vdb
fs_type: ext4
label: gpt
number: 1
state: present
when: disk_check.stat.exists
- name: Formatear la partición en ext4
community.general.filesystem:
fstype: ext4
dev: /dev/vdb1
when: disk_check.stat.exists
- name: Obtener UUID del disco
ansible.builtin.command: blkid -s UUID -o value /dev/vdb1
register: disk_uuid
when: disk_check.stat.exists
- name: Montar disco en /mnt/data
ansible.posix.mount:
path: /mnt/data
src: UUID={{ disk_uuid.stdout }}
fstype: ext4
state: "mounted"
when: disk_check.stat.exists
- name: Crear carpeta para longhorn
ansible.builtin.file:
path: /mnt/data/longhorn
state: directory
mode: '0755'
- name: Crear carpeta para postgres
ansible.builtin.file:
path: /mnt/data/postgres
state: directory
mode: '0755'

View File

@@ -0,0 +1,18 @@
- name: Configurar carpetas para longhorn y postrges
hosts: k3s_cluster
become: yes
collections:
- community.general
tasks:
- name: Crear carpeta para longhorn
ansible.builtin.file:
path: /mnt/data/longhorn
state: directory
mode: '0755'
- name: Crear carpeta para postgres
ansible.builtin.file:
path: /mnt/data/postgres
state: directory
mode: '0755'

59
ansible/k3s/install.yml Normal file
View File

@@ -0,0 +1,59 @@
- name: Instalar K3s en el Cluster
hosts: k3s_cluster
become: true
tasks:
- name: Actualizar paquetes
ansible.builtin.apt:
update_cache: true
upgrade: true
- name: Instalar dependencias
ansible.builtin.apt:
name:
- curl
- vim
- unzip
- nfs-common
- name: Descargar instalador de K3s si no existe
ansible.builtin.get_url:
url: https://get.k3s.io
dest: /tmp/k3s-install.sh
mode: '0755'
register: k3s_install_script
- name: Instalar K3s en master
ansible.builtin.command: /tmp/k3s-install.sh server --disable=servicelb
args:
creates: /usr/local/bin/k3s
when: inventory_hostname in groups['k3s_master']
- name: Obtener el token de K3s
ansible.builtin.command: cat /var/lib/rancher/k3s/server/node-token
register: k3s_token
changed_when: false
delegate_to: "{{ groups['k3s_master'][0] }}"
- name: Instalar K3s en nodos worker
ansible.builtin.command: /tmp/k3s-install.sh
args:
creates: /usr/local/bin/k3s
environment:
K3S_URL: "https://{{ hostvars[groups['k3s_master'][0]]['inventory_hostname'] }}:6443"
K3S_TOKEN: "{{ k3s_token.stdout }}"
when: inventory_hostname in groups['k3s_workers']
- name: Copiar kubeconfig al host local
ansible.builtin.fetch:
src: /etc/rancher/k3s/k3s.yaml
dest: ../kubeconfig.yaml
flat: true
delegate_to: "{{ groups['k3s_master'][0] }}"
- name: Ajustar kubeconfig para acceso externo
ansible.builtin.replace:
path: ../kubeconfig.yaml
regexp: '127.0.0.1'
replace: "{{ hostvars[groups['k3s_master'][0]]['inventory_hostname'] }}"
delegate_to: localhost

View File

@@ -0,0 +1,16 @@
- name: Desinstalar K3s en el Cluster
hosts: k3s_cluster
become: yes
tasks:
- name: Desinstalar K3s en los nodos master
shell: |
/usr/local/bin/k3s-uninstall.sh
when:
- inventory_hostname in groups['k3s_master']
- name: Desinstalar K3s en los nodos workers
shell: |
/usr/local/bin/k3s-agent-uninstall.sh
when:
- inventory_hostname in groups['k3s_workers']