2024-10-25 03:25:58 +02:00
|
|
|
- hosts: all
|
|
|
|
become: true
|
|
|
|
tasks:
|
|
|
|
- name: Actualizamos el sistema
|
|
|
|
apt: update_cache=yes upgrade=yes
|
2024-10-30 09:03:16 +01:00
|
|
|
- name: nos aseguramos de que curl esté instalado
|
2024-10-25 03:25:58 +02:00
|
|
|
apt:
|
|
|
|
pkg:
|
|
|
|
- curl
|
|
|
|
|
|
|
|
- hosts: planos_control
|
|
|
|
become: true
|
|
|
|
tasks:
|
2024-10-30 09:03:16 +01:00
|
|
|
# Para que no haya problemas de certificados al usar kubectl, añadimos la IP del plano de control durante la instalación de k3s.
|
2024-10-30 08:05:02 +01:00
|
|
|
- name: instalamos k3s
|
|
|
|
shell: "curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC='--tls-san {{ ip_pcontrol }}' sh -"
|
2024-10-25 03:25:58 +02:00
|
|
|
- name: sacar token
|
|
|
|
ansible.builtin.slurp:
|
|
|
|
src: "/var/lib/rancher/k3s/server/node-token"
|
|
|
|
register: token_k3s_base64
|
|
|
|
- name: descodificar token
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
token_k3s: "{{ token_k3s_base64.content | ansible.builtin.b64decode | replace('\n', '' ) }}"
|
|
|
|
- debug: msg="el token es {{token_k3s}}"
|
|
|
|
|
|
|
|
- hosts: trabajadores
|
|
|
|
become: true
|
|
|
|
tasks:
|
2024-10-30 08:05:02 +01:00
|
|
|
- name: instalamos k3s con el token
|
|
|
|
shell: "curl -sfL https://get.k3s.io | K3S_URL=https://{{ ip_pcontrol }}:6443 K3S_TOKEN={{ hostvars['p_nodo'].token_k3s }} sh -"
|