First commit
This commit is contained in:
59
ansible/k3s/install.yml
Normal file
59
ansible/k3s/install.yml
Normal 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
|
||||
Reference in New Issue
Block a user