--- - name: Actualizar el archivo /etc/hosts en todos los equipos del inventario 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 register: current_hosts - name: Generar el contenido actualizado del archivo /etc/hosts ansible.builtin.template: src: templates/hosts.j2 dest: /etc/hosts owner: root group: root 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 - name: Reiniciar las maquinas reboot: reboot_timeout: 300