From 4acf7872b84d431ce1e8b9c4cf68a6025fddaec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Rodr=C3=ADguez?= Date: Fri, 25 Oct 2024 03:25:58 +0200 Subject: [PATCH] creados ficheros ansible --- Vagrantfile | 4 ++-- ansible/ansible.cfg | 3 +++ ansible/hosts | 18 ++++++++++++------ ansible/site.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 ansible/ansible.cfg create mode 100644 ansible/site.yaml diff --git a/Vagrantfile b/Vagrantfile index 6f7ea63..d7e1761 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -3,8 +3,8 @@ Vagrant.configure("2") do |config| config.vm.box_check_update = false config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.provider "libvirt" do |v| - v.memory = 2048 - v.cpus = 3 + v.memory = 4096 + v.cpus = 4 v.driver = "qemu" end config.vm.define "plano-control" do |pcontrol| diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..b16ea3d --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +inventory = hosts +host_key_checking = False diff --git a/ansible/hosts b/ansible/hosts index 8497f99..308ea07 100644 --- a/ansible/hosts +++ b/ansible/hosts @@ -4,15 +4,21 @@ all: hosts: p_nodo: ansible_ssh_host: 192.168.121.234 - ansible_ssh_user: debian - ansible_ssh_private_key_file: ~/.ssh/id_rsa + ansible_ssh_user: vagrant + ansible_ssh_private_key_file: ../.vagrant/machines/plano-control/libvirt/private_key trabajadores: hosts: nodo1: ansible_ssh_host: 192.168.121.157 - ansible_ssh_user: debian - ansible_ssh_private_key_file: ~/.ssh/id_rsa + ansible_ssh_user: vagrant + ansible_ssh_private_key_file: ../.vagrant/machines/nodo1/libvirt/private_key nodo2: ansible_ssh_host: 192.168.121.33 - ansible_ssh_user: debian - ansible_ssh_private_key_file: ~/.ssh/id_rsa \ No newline at end of file + ansible_ssh_user: vagrant + 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" \ No newline at end of file diff --git a/ansible/site.yaml b/ansible/site.yaml new file mode 100644 index 0000000..c61dae5 --- /dev/null +++ b/ansible/site.yaml @@ -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 }}"