creados ficheros ansible

This commit is contained in:
Roberto Rodríguez 2024-10-25 03:25:58 +02:00
parent 70e5e24f38
commit 4acf7872b8
4 changed files with 58 additions and 8 deletions

4
Vagrantfile vendored
View File

@ -3,8 +3,8 @@ Vagrant.configure("2") do |config|
config.vm.box_check_update = false config.vm.box_check_update = false
config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "libvirt" do |v| config.vm.provider "libvirt" do |v|
v.memory = 2048 v.memory = 4096
v.cpus = 3 v.cpus = 4
v.driver = "qemu" v.driver = "qemu"
end end
config.vm.define "plano-control" do |pcontrol| config.vm.define "plano-control" do |pcontrol|

3
ansible/ansible.cfg Normal file
View File

@ -0,0 +1,3 @@
[defaults]
inventory = hosts
host_key_checking = False

View File

@ -4,15 +4,21 @@ all:
hosts: hosts:
p_nodo: p_nodo:
ansible_ssh_host: 192.168.121.234 ansible_ssh_host: 192.168.121.234
ansible_ssh_user: debian ansible_ssh_user: vagrant
ansible_ssh_private_key_file: ~/.ssh/id_rsa ansible_ssh_private_key_file: ../.vagrant/machines/plano-control/libvirt/private_key
trabajadores: trabajadores:
hosts: hosts:
nodo1: nodo1:
ansible_ssh_host: 192.168.121.157 ansible_ssh_host: 192.168.121.157
ansible_ssh_user: debian ansible_ssh_user: vagrant
ansible_ssh_private_key_file: ~/.ssh/id_rsa ansible_ssh_private_key_file: ../.vagrant/machines/nodo1/libvirt/private_key
nodo2: nodo2:
ansible_ssh_host: 192.168.121.33 ansible_ssh_host: 192.168.121.33
ansible_ssh_user: debian ansible_ssh_user: vagrant
ansible_ssh_private_key_file: ~/.ssh/id_rsa ansible_ssh_private_key_file: ../.vagrant/machines/nodo2/libvirt/private_key
vars:
fichero: "/home/vagrant/k3s.sh"
token_k3s: ""
token_k3s_base64: ""
ip_pcontrol: "10.10.10.10"

41
ansible/site.yaml Normal file
View File

@ -0,0 +1,41 @@
- 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
- name: Descargar instalador k3s
get_url:
url: https://get.k3s.io
dest: "{{ fichero }}"
- name: Dar permisos de ejecución al instalador k3s
file:
path: "{{ fichero }}"
mode: '0755'
- name: Ejecutar instalador k3s
shell: "{{ fichero }}"
- name: Borrar instalador k3s
file:
path: "{{ fichero }}"
state: absent
- hosts: planos_control
become: true
tasks:
- 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: Ejecutar instalador k3s
shell: "k3s agent --server https://{{ ip_pcontrol }}:6443 --token {{ token_k3s }}"