k3s-ansible/ansible/site.yaml

30 lines
976 B
YAML

- hosts: all
become: true
tasks:
- name: Actualizamos el sistema
apt: update_cache=yes upgrade=yes
- name: instalación de k3s- nos aseguramos de que curl esté instalado
apt:
pkg:
- curl
- hosts: planos_control
become: true
tasks:
- name: instalamos k3s
shell: "curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC='--tls-san {{ ip_pcontrol }}' sh -"
- 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:
- 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 -"