procedures_ansible_guia_de_arquitectura_verificacion
This is an old revision of the document!
Table of Contents
Ansible Automation Server — Arquitectura Final y Guía de Verificación
Objetivo
Este documento describe el estado final operativo y validado del servidor Ansible. Su propósito es servir como:
- Guía mínima de verificación de arquitectura
- Referencia técnica oficial
- Manual de reconstrucción del entorno
- Base de auditoría y troubleshooting
- Fuente de verdad del servidor
1. Arquitectura General
- OS: Linux (Debian / Ubuntu)
- Usuario operativo: root
- Path base Ansible: /server/ansible
- Python: entorno virtual (venv)
- Automatización:
- Ansible (network_cli / ssh)
- Expect (fallback controlado)
- Métodos de conexión:
- libssh (preferido)
- paramiko (fallback)
- ssh clásico (Instant / Controllers)
2. Árbol de Directorios FINAL
/server/ansible
├── ansible.cfg
├── requirements.yml
├── venv/
│ └── bin/activate
├── inventory/
│ ├── hosts_north
│ ├── hosts_north_1
│ ├── hosts_south
│ ├── hosts_south_1
│ └── group_vars/
│ ├── all.yml
│ ├── north.yml
│ └── south.yml
├── playbooks/
│ ├── backup_all_north.yml
│ ├── backup_all_south.yml
│ ├── backup_instant_south.yml
│ ├── backup_switches_north.yml
│ ├── backup_switches_south.yml
│ ├── backup_wlan_controller_north.yml
│ ├── get_arp_north.yml
│ ├── get_arp_south.yml
│ ├── report_inventory_north.yml
│ └── report_inventory_south.yml
├── scripts/
│ ├── knownhosts_north.sh
│ ├── knownhosts_south.sh
│ ├── knownhosts_update.sh
│ ├── aoss_2930_backup.expect
│ ├── aoss_2930_backup_1.expect
│ └── instant_backup.expect
├── logs/
│ └── known_hosts/
├── tmp/
│ └── *.debug
└── backups/
├── cli_backup/
└── Report_inventory/
├── NORTH/
└── SOUTH/
/root/.ssh
├── known_hosts
├── known_hosts.bak.*
└── authorized_keys (opcional)
3. /root/.ssh — Componente CRÍTICO
¿Por qué es obligatorio?
El directorio /root/.ssh es utilizado directamente por:
- Ansible (`network_cli`)
- libssh / paramiko
- SSH clásico
- Scripts Expect
- Scripts de actualización de host keys
Sin esta ruta correctamente configurada:
- libssh puede fallar silenciosamente
- SSH puede rechazar conexiones
- Expect puede abortar por mismatch de host key
- Ansible puede quedar inconsistente entre nodos
Este diseño centraliza el control de confianza SSH del servidor.
4. Estructura y Permisos SSH
/root/.ssh ├── known_hosts → Claves públicas de todos los dispositivos ├── known_hosts.bak.* → Backups automáticos por script └── authorized_keys → (opcional) acceso por llave
Permisos OBLIGATORIOS:
chmod 700 /root/.ssh chmod 600 /root/.ssh/known_hosts
—
5. Gestión de known_hosts
Scripts disponibles
- knownhosts_north.sh
- knownhosts_south.sh
- knownhosts_update.sh ← método recomendado
Estos scripts:
- Extraen IPs desde inventarios
- Limpian entradas antiguas
- Ejecutan ssh-keyscan
- Deduplican claves
- Generan backups
- Evitan ejecuciones simultáneas (lock)
Ejecución recomendada
/server/ansible/scripts/knownhosts_update.sh \ /server/ansible/inventory/hosts_north north
Resultados esperados:
- /root/.ssh/known_hosts actualizado
- Backup automático con timestamp
- Logs en /server/ansible/logs/known_hosts/
—
6. Entorno Virtual y Dependencias
Activación
cd /server/ansible source venv/bin/activate
Dependencias del sistema (una sola vez)
apt-get update apt-get install -y \ build-essential \ pkg-config \ libssh-dev \ libssl-dev \ python3-dev
Python / pylibssh
python -m pip install -U pip setuptools wheel python -m pip install ansible-pylibssh
Verificación
python -c "import pylibsshext; print('OK pylibsshext')" ansible --version
7. Ansible Galaxy — Collections
collections: - name: arubanetworks.aoscx - name: arubanetworks.aos_switch - name: dellemc.os6 - name: cisco.ios - name: ansible.netcommon - name: ansible.utils
Instalación:
ansible-galaxy collection install \ -r /server/ansible/requirements.yml \ -p /server/ansible/collections \ --force
8. Relación SSH ↔ Expect ↔ Ansible
| Componente | Usa /root/.ssh | Motivo |
| ———– | ————— | ——– |
| Ansible network_cli | Sí | Validación host key |
| libssh | Sí | Trust store |
| paramiko | Sí | Known hosts |
| Expect | Sí | StrictHostKeyChecking |
| ssh-keyscan | Sí | Población automática |
—
9. Checklist SSH (CRÍTICO)
✔ /root/.ssh existe ✔ Permisos correctos ✔ known_hosts no vacío ✔ known_hosts actualizado desde inventarios ✔ ssh-keyscan funciona ✔ Expect conecta sin prompt de host key
—
10. Estado Final
Este servidor queda:
- OPERATIVO
- REPRODUCIBLE
- AUDITABLE
- RESILIENTE A CAMBIOS DE HOST KEY
- APTO PARA PRODUCCIÓN
La ruta /root/.ssh es parte integral de la arquitectura y no debe ser omitida en ninguna reinstalación.
procedures_ansible_guia_de_arquitectura_verificacion.1768798467.txt.gz · Last modified: by aperez
