Browse Source

añadido teclado en español

pulitux 1 year ago
parent
commit
367ba259fb

File diff suppressed because it is too large
+ 0 - 0
.vagrant/bundler/global.sol


+ 0 - 1
.vagrant/machines/router_1/virtualbox/action_provision

@@ -1 +0,0 @@
-1.5:63898e54-e2f1-46ac-94b1-3aa2c5e58343

+ 0 - 1
.vagrant/machines/router_1/virtualbox/action_set_name

@@ -1 +0,0 @@
-1727047642

+ 0 - 1
.vagrant/machines/router_1/virtualbox/box_meta

@@ -1 +0,0 @@
-{"name":"pulitux/csr1kv","version":"17.03.04","provider":"virtualbox","directory":"boxes/pulitux-VAGRANTSLASH-csr1kv/17.03.04/amd64/virtualbox"}

+ 0 - 1
.vagrant/machines/router_1/virtualbox/creator_uid

@@ -1 +0,0 @@
-1000

+ 0 - 1
.vagrant/machines/router_1/virtualbox/id

@@ -1 +0,0 @@
-63898e54-e2f1-46ac-94b1-3aa2c5e58343

+ 0 - 1
.vagrant/machines/router_1/virtualbox/index_uuid

@@ -1 +0,0 @@
-53538b1ff9f74f6daeea05fe21b7cf15

+ 0 - 1
.vagrant/machines/router_1/virtualbox/synced_folders

@@ -1 +0,0 @@
-{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/home/pulitux/net_labs/wstations","disabled":false,"__vagrantfile":true}}}

+ 0 - 1
.vagrant/machines/router_1/virtualbox/vagrant_cwd

@@ -1 +0,0 @@
-/home/pulitux/net_labs/wstations

+ 0 - 6
.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory

@@ -1,6 +0,0 @@
-# Generated by Vagrant
-
-router_1 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/home/pulitux/.vagrant.d/insecure_private_keys/vagrant.key.ed25519'
-
-[routers]
-router_1

+ 0 - 12
.vagrant/rgloader/loader.rb

@@ -1,12 +0,0 @@
-# Copyright (c) HashiCorp, Inc.
-# SPDX-License-Identifier: BUSL-1.1
-
-# This file loads the proper rgloader/loader.rb file that comes packaged
-# with Vagrant so that encoded files can properly run with Vagrant.
-
-if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
-  require File.expand_path(
-    "rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"])
-else
-  raise "Encoded files can't be read outside of the Vagrant installer."
-end

+ 51 - 43
Vagrantfile

@@ -2,32 +2,21 @@ Vagrant.configure("2") do |config|
   # Configuración general de las maquinas
   config.vm.provider "virtualbox" do |v|
     v.linked_clone = true
-    v.customize ["modifyvm", :id, "--groups", "/lab1"]
-    v.customize ["modifyvm", :id, "--pagefusion", "on"]
+    # v.synced_folder ".", "/vagrant", disabled: true  # Deshabilitar sincronización de carpetas
+    v.customize ["modifyvm", :id, "--groups", "/lab1"]  # Crear todas las maquinas agrupadas  en "lab1"
+    v.customize ["modifyvm", :id, "--pagefusion", "on"] # Habilitar la compartición de paginas de memoria entre maquinas
   end
   
-  # config.vm.provision :ansible do |ansible|
-  #   # Definicion de los grupos de maquinas
-  #   ansible.groups = {
-  #     "red_1" => ["router_1", "workstation_1", "server_1_[1:2]"],
-  #     "red_2" => ["router_2", "workstation_2", "server_2_[1:2]"],
-  #     "workstations" => ["workstation_1", "workstation_2"],
-  #     "routers" => ["router_1", "router_2"],
-  #     "servers" => ["server_[1:2]_[1:2]"],
-  #     "computers:children" => ["workstations", "servers"]
-  #   }
-  #   ansible.playbook = "provision/computers.yml"
-  # end
-
   (1..2).each do |j|
 
     ##################################
-    # Creación de los routers router_
+    # Creación de los routers cisco
     ##################################
 
-    config.vbguest.auto_update = false
-    config.ssh.insert_key = false
+    config.vbguest.auto_update = false  # Necesario por no existir vbgest para los routers
+    config.ssh.insert_key = false       # Necesario para evitar errores de autenticacion
     config.vm.define "router_#{j}" do |router|
+      router.vbguest.auto_update = false
       router.vm.box = "pulitux/csr1kv"
       router.vm.box_version = "17.03.04"
       router.vm.hostname = "router#{j}"
@@ -37,12 +26,15 @@ Vagrant.configure("2") do |config|
         vb.name = "router_#{j}"
         vb.memory = "2048"
       end
-      router.vm.provision :ansible do |ansible|
-        ansible.limit = "routers"
-        ansible.playbook = "provision/routers.yml"
-        ansible.groups = {
-          "routers" => ["router_1", "router_2"]
-        }
+
+      if j == 2   # Configurar todas tras crear el último router
+        router.vm.provision "routers", type: :ansible do |ansible|
+          ansible.limit = "routers"
+          ansible.playbook = "provision/routers.yml"
+          ansible.groups = {
+            "routers" => ["router_1", "router_2"]
+          }
+        end
       end
     end
 
@@ -50,20 +42,24 @@ Vagrant.configure("2") do |config|
     # Creación de las máquinas Workstations Ubuntu
     ################################################
 
-    config.vm.define "workstation_#{j}" do |workstation_|
-      workstation_.vm.box = "ubuntu/jammy64"
-      workstation_.vm.hostname = "workstation#{j}"
-      workstation_.vm.network "private_network", ip: "10.1.#{j}.100", auto_config: false
-      workstation_.vm.provider "virtualbox" do |vb|
+    config.vm.define "workstation_#{j}" do |workstation|
+    # workstation.vbguest.auto_update = true
+    workstation.vm.box = "ubuntu/jammy64"
+      workstation.vm.hostname = "workstation#{j}"
+      workstation.vm.network "private_network", ip: "10.1.#{j}.100"
+      workstation.vm.provider "virtualbox" do |vb|
         vb.name = "workstation_#{j}"
         vb.memory = "2048"
       end
-      workstation_.vm.provision :ansible do |ansible|
-        ansible.limit = "workstations"
-        ansible.playbook = "provision/workstations.yml" 
-        ansible.groups = {
-          "workstations" => ["workstation_1", "workstation_2"]
-        }
+      if j == 2   # Configurar todas tras crear la última workstation
+        workstation.vm.provision  "workstations", type: :ansible do |ansible|
+          ansible.limit = "workstations"
+          ansible.playbook = "provision/workstations.yml" 
+          ansible.groups = {
+            "workstations" => ["workstation_1", "workstation_2"]
+          }
+        end
+      end
     end
 
     ####################################################
@@ -74,20 +70,32 @@ Vagrant.configure("2") do |config|
       config.vm.define "server_#{j}_#{i}" do |server|
         server.vm.box = "ubuntu/jammy64"
         server.vm.hostname = "server#{j}#{i}"
-        server.vm.network "private_network", ip: "10.1.#{j}.10#{i}", auto_config: false
+        server.vm.network "private_network", ip: "10.1.#{j}.10#{i}" #, auto_config: false
         server.vm.provider "virtualbox" do |vb|
           vb.memory ="512"
           vb.name = "server_#{j}_#{i}"
         end
-        server.vm.provision :ansible do |ansible|
-          ansible.limit = "servers"
-          ansible.playbook = "provision/servers.yml"
-          ansible.groups = {
-            "servers" => ["server_[1:2]_[1:2]"]
-          }
+        if j == 2 and i == 2   # Ejecutar tras crear el último server
+          server.vm.provision "servers", type: :ansible do |ansible|
+            ansible.limit = "servers"
+            ansible.playbook = "provision/servers.yml"
+            ansible.groups = {
+              "servers" => ["server_[1:2]_[1:2]"]
+              }
+          end
+
+          # Ejecutar la configuración de todos los computadores
+          server.vm.provision :ansible, after: "servers" do |ansible|
+            ansible.limit = "computers"
+            ansible.playbook = "provision/computers.yml"
+            ansible.groups = {
+              "workstations" => ["workstation_1", "workstation_2"],
+              "servers" => ["server_[1:2]_[1:2]"],
+              "computers:children" => ["workstations", "servers"]
+                }
+          end
         end
       end
     end
   end
 end
-end

+ 103 - 9
provision/computers.yml

@@ -1,8 +1,98 @@
 ---
 - name: Actualizar el archivo /etc/hosts en todos los equipos del inventario
-  hosts: equipos
+  hosts: computers
   become: yes
   tasks:
+    - name: Eliminar el usuario ubuntu de los hosts
+      ansible.builtin.user:
+        name: ubuntu
+        state: absent
+
+    - name: touch
+      file:
+        path: /etc/network/interfaces
+        state: touch
+
+    # - name: Ensure localisation files for es_ES.UTF-8 are available
+    #   locale_gen:
+    #     name: es_ES.UTF-8
+    #     state: present
+
+    # - name: Ensure localisation files for es_ES.UTF-8 are available
+    #   locale_gen:
+    #     name: es_ES.UTF-8
+    #     state: present
+
+    # - name: Get current locale and language configuration
+    #   command: localectl status
+    #   register: locale_status
+    #   changed_when: false
+
+    # - name: Parse 'LANG' from current locale and language configuration
+    #   set_fact:
+    #     locale_lang: "{{ locale_status.stdout | regex_search('LANG=([^\n]+)', '\\1') | first }}"
+
+    # - name: Parse 'LANGUAGE' from current locale and language configuration
+    #   set_fact:
+    #     locale_language: "{{ locale_status.stdout | regex_search('LANGUAGE=([^\n]+)', '\\1') | default([locale_lang], true) | first }}"
+
+    # - name: Configure locale to es_ES.UTF-8 and language to es_ES.UTF-8
+    #   become: yes
+    #   command: localectl set-locale LANG=es_ES.UTF-8 LANGUAGE=es_ES.UTF-8
+    #   # changed_when: locale_lang != es_ES.UTF-8 or locale_language != es_ES.UTF-8
+
+    - name: Configurar la interfaz enp0s8 con una IP estática
+      ansible.builtin.lineinfile:
+        path: /etc/default/keyboard
+        regexp: '^XKBLAYOUT='
+        line: 'XKBLAYOUT="es"'
+        backup: yes
+
+    - name: Configurar teclado en español
+      ansible.builtin.lineinfile:
+        path: /etc/network/interfaces
+        regexp: '^iface enp0s8 inet'
+        line: 'iface enp0s8 inet static'
+        backup: yes
+
+    - name: Agregar configuración IP estática
+      ansible.builtin.blockinfile:
+        path: /etc/network/interfaces
+        marker: "# {mark} ANSIBLE MANAGED BLOCK"
+        block: |
+          address {{ eth1_ip }}
+          netmask {{ eth1_gw }}
+          gateway {{ eth1_dns}}
+      vars:
+        eth1_ip: " {{ ipv4_ip }} "
+        eth1_gw: "{{ ipv4_gw }}"
+        eth1_dns: "{{ ipv4_dns }}"
+
+    # - name: Reiniciar el servicio de red para aplicar los cambios
+    #   ansible.builtin.service:
+    #     name: networking
+    #     state: restarted
+
+    # - name: Instalar el paquete network-manager
+    #   apt:
+    #     name: network-manager
+    #     state: present
+    #     update_cache: yes
+
+    # - name: Configurar el adaptador de red eth1 con al configuracion existente en host_vars
+    #   community.general.nmcli:
+    #     conn_name: enp0s8
+    #     ifname: enp0s8
+    #     type: ethernet
+    #     ip4: "{{ eth1_ip }}"
+    #     gw4: "{{ eth1_gw }}"
+    #     dns4: "{{ eth1_dns }}"
+    #     state: present
+    #   vars: 
+    #     eth1_ip: " {{ ipv4_ip }} "
+    #     eth1_gw: "{{ ipv4_gw }}"
+    #     eth1_dns: "{{ ipv4_dns }}"
+        
     - name: Leer el contenido actual del archivo /etc/hosts
       ansible.builtin.slurp:
         path: /etc/hosts
@@ -17,11 +107,15 @@
         mode: '0644'
       vars:
         current_hosts_content: "{{ current_hosts.content | b64decode }}"
-      notify:
-        - Reiniciar servicio de red si es necesario
-
-  handlers:
-    - name: Reiniciar servicio de red si es necesario
-      ansible.builtin.service:
-        name: network
-        state: restarted
+  #     notify:
+  #       - Reiniciar servicio de red si es necesario
+
+  # handlers:
+  #   - name: Reiniciar servicio de red si es necesario
+  #     ansible.builtin.service:
+  #       name: network
+  #       state: restarted
+    - name: Reiniciar las maquinas
+      reboot:
+        reboot_timeout: 300
+

+ 3 - 0
provision/host_vars/server_1_1.yml

@@ -0,0 +1,3 @@
+ipv4_ip: 10.1.1.102/24
+ipv4_gw: 10.1.1.1
+ipv4_dns: 8.8.8.8

+ 3 - 0
provision/host_vars/server_1_2.yml

@@ -0,0 +1,3 @@
+ipv4_ip: 10.1.1.102/24
+ipv4_gw: 10.1.1.1
+ipv4_dns: 8.8.8.8

+ 3 - 0
provision/host_vars/server_2_1.yml

@@ -0,0 +1,3 @@
+ipv4_ip: 10.1.2.101/24
+ipv4_gw: 10.1.2.1
+ipv4_dns: 8.8.8.8

+ 3 - 0
provision/host_vars/server_2_2.yml

@@ -0,0 +1,3 @@
+ipv4_ip: 10.1.2.102/24
+ipv4_gw: 10.1.2.1
+ipv4_dns: 8.8.8.8

+ 3 - 0
provision/host_vars/workstation_1.yml

@@ -0,0 +1,3 @@
+ipv4_ip: 10.1.1.100/24
+ipv4_gw: 10.1.1.1
+ipv4_dns: 8.8.8.8

+ 3 - 0
provision/host_vars/workstation_2.yml

@@ -0,0 +1,3 @@
+ipv4_ip: 10.1.2.100/24
+ipv4_gw: 10.1.2.1
+ipv4_dns: 8.8.8.8

+ 34 - 19
provision/routers.yml

@@ -6,36 +6,51 @@
   vars: # for execution environment
     ansible_connection: ansible.netcommon.network_cli
     ansible_network_os: cisco.ios.ios
+    ansible_user: vagrant
+    ansible_password: vagrant
   
   tasks:
     - name: Configurar interfaces GigabitEthernet
       ansible.netcommon.cli_command:
-        command:
-          - "interface GigabitEthernet1"
-          - "ip address {{ wan_ip }} 255.255.255.0"
-          - "no shutdown"
-          - "exit"
-          - "interface GigabitEthernet2"
-          - "ip address {{ lan_ip }} 255.255.255.0"
-          - "no shutdown"
-          - "exit"
+        command: "{{ item }}"
+      loop:
+        - "enable"
+        - "configure terminal"
+        - "interface GigabitEthernet1"
+        - "ip address {{ wan_ip }} 255.255.255.0"
+        - "no shutdown"
+        - "exit"
+        - "interface GigabitEthernet2"
+        - "ip address {{ lan_ip }} 255.255.255.0"
+        - "no shutdown"
+        - "exit"
       vars:
         wan_ip: "{{ wan_interface_ip }}"
         lan_ip: "{{ lan_interface_ip }}"
     
     - name: Configurar RIPv2 en el router
       ansible.netcommon.cli_command:
-        command:
-          - "router rip"
-          - "version 2"
-          - "network {{ wan_network }}"
-          - "network {{ lan_network }}"
-          - "no auto-summary"
+        command: "{{ item }}"
+      loop:
+        - "enable"
+        - "configure terminal"
+        - "router rip"
+        - "version 2"
+        - "network {{ wan }}"
+        - "network {{ lan }}"
+        - "no auto-summary"
       vars:
-        wan_network: "{{ wan_network }}"
-        lan_network: "{{ lan_network }}"
+        wan: "{{ wan_network }}"
+        lan: "{{ lan_network }}"
 
     - name: Guardar la configuración en la NVRAM
       ansible.netcommon.cli_command:
-        command:
-          - "write memory"
+        command: "{{ item }}"
+      loop:
+        - "enable"
+        # - "configure terminal"
+        - "write memory"
+
+    # - name: Reiniciar los routers
+    #   reboot:
+    #     reboot_timeout: 300

+ 2 - 2
provision/templates/hosts.j2

@@ -4,6 +4,6 @@
 {{ current_hosts_content }}
 
 # Información de todos los hosts del inventario
-{% for host in groups['all'] %}
-{{ hostvars[host]['ansible_host'] }} {{ host }} {{ hostvars[host]['ansible_fqdn'] | default('') }}
+{% for host in groups['computers'] %}
+{{ hostvars[host]['ansible_facts']['enp0s8']['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {{ hostvars[host]['ansible_fqdn'] | default('') }} 
 {% endfor %}

+ 0 - 3
provision/workstations.yml

@@ -28,6 +28,3 @@
       apt:
         name: wireshark
         state: present
-    - name: Reiniciar las maquinas
-      reboot:
-        reboot_timeout: 300

+ 2 - 0
times

@@ -0,0 +1,2 @@
+mar 01 oct 2024 10:02:07 CEST
+mar 01 oct 2024 10:11:13 CEST

+ 4 - 0
todo

@@ -0,0 +1,4 @@
+instalar net_tools
+configurar español
+crear usuario alumno
+

Some files were not shown because too many files changed in this diff