alliance-boreale/docs/guides/guide-netbox.md
Dan Allaire 81dbfb1d04
Some checks are pending
CI / yaml-lint (push) Waiting to run
CI / ssot-export (push) Waiting to run
CI / tests (push) Waiting to run
CI / docs (push) Waiting to run
extension .md - correction
2025-10-31 14:50:26 -04:00

5.6 KiB
Raw Blame History

MANUEL DE LOPÉRATEUR NETBOX PRODUCTION

Version : 1.0 31/10/2025
Infrastructure : Debian 12 sans Docker Ansible + Forgejo + nftables


OBJECTIF

Ce manuel te permet de créer, maintenir, dépanner et détruire un serveur NetBox de production en 5 minutes, de façon reproductible, sécurisée, et sans boîte noire.


PRÉREQUIS (avant de commencer)

Élément Détail
VM Debian 12 Bookworm (genericcloud)
Compte ansible avec clé SSH publique dans ~/.ssh/authorized_keys
Sudo ansible ALL=(ALL) NOPASSWD: ALL dans /etc/sudoers.d/ansible
Réseau IP fixe + DNS A record → netbox.tondomaine.com
Forgejo Repo netbox-deploy cloné localement ou via SSH
Ansible ansible >= 2.14 installé sur ton poste ou runner Forgejo
Vault Mot de passe Ansible Vault stocké dans Forgejo SecretsANSIBLE_VAULT_PASS

1. CRÉER UN NOUVEAU SERVEUR NETBOX (5 min)

Étapes

# 1. Cloner le repo (si pas déjà fait)
git clone ssh://git@forgejo.tondomaine.com/tonuser/netbox-deploy.git
cd netbox-deploy

# 2. Ajouter la nouvelle VM dans linventaire
nano inventories/production/hosts
[netbox]
netbox-prod2 ansible_host=203.0.113.42 ansible_user=ansible
# 3. (Optionnel) Personnaliser les variables
cp inventories/production/group_vars/all.yml inventories/production/host_vars/netbox-prod2.yml
nano inventories/production/host_vars/netbox-prod2.yml

→ Modifie :

netbox_domain: netbox2.tondomaine.com
letsencrypt_email: admin@tondomaine.com
# 4. Lancer le déploiement
ansible-playbook -i inventories/production/hosts site.yml \
  --limit netbox-prod2 \
  --vault-password-file <(echo $ANSIBLE_VAULT_PASS)

Résultat : NetBox accessible sur https://netbox2.tondomaine.com en moins de 5 min


2. OPÉRATIONS COURANTES

Action Commande
Vérifier le service sudo systemctl status netbox
Redémarrer NetBox sudo systemctl restart netbox
Voir les logs journalctl -u netbox -f
Accéder à la DB sudo -u postgres psql -d netbox
Backup manuel sudo -u postgres pg_dump netbox > /opt/netbox/backups/netbox-$(date +%F).sql
Vérifier nftables sudo nft list ruleset
Renouveler SSL sudo certbot renew
Mettre à jour NetBox Voir §3

3. MISE À JOUR NETBOX (sécurisée)

Playbook dédié : upgrade.yml

# upgrade.yml
- name: Mettre à jour NetBox
  hosts: netbox
  become: yes
  tasks:
    - name: Stopper NetBox
      systemd: name=netbox state=stopped

    - name: Pull dernière version
      git:
        repo: https://github.com/netbox-community/netbox.git
        dest: /opt/netbox/src
        version: "v4.1.0"  # ← change ici
      become_user: netbox

    - name: Mettre à jour dépendances
      pip:
        requirements: /opt/netbox/src/requirements.txt
        virtualenv: /opt/netbox/venv
      become_user: netbox

    - name: Migrer DB
      command: /opt/netbox/venv/bin/python manage.py migrate
      args: { chdir: /opt/netbox/src/netbox }
      become_user: netbox

    - name: Collect static
      command: /opt/netbox/venv/bin/python manage.py collectstatic --no-input
      args: { chdir: /opt/netbox/src/netbox }
      become_user: netbox

    - name: Démarrer NetBox
      systemd: name=netbox state=started
ansible-playbook -i inventories/production/hosts upgrade.yml \
  --vault-password-file <(echo $ANSIBLE_VAULT_PASS)

4. DÉPANNAGE RAPIDE

Symptôme Diagnostic Solution
502 Bad Gateway Nginx → Gunicorn down sudo systemctl status netboxrestart netbox
Login refusé Mauvais mot de passe Réinitialiser : python manage.py shellUser.objects.filter(username='admin').first().set_password('nouveau')
DB erreur PostgreSQL down sudo systemctl status postgresql
SSL expiré Certbot échoue sudo certbot renew --dry-run → corrige DNS
IP bloquée nftables sudo nft list ruleset → ajoute règle temporaire

5. SAUVEGARDE & RESTAURATION

Backup automatique (cron)

# /etc/cron.daily/netbox-backup
#!/bin/bash
BACKUP_DIR="/opt/netbox/backups"
DATE=$(date +%F)
sudo -u postgres pg_dump netbox > $BACKUP_DIR/netbox-$DATE.sql
find $BACKUP_DIR -name "*.sql" -mtime +30 -delete
chmod +x /etc/cron.daily/netbox-backup

Restauration

sudo -u postgres psql -d netbox < /opt/netbox/backups/netbox-2025-10-31.sql

6. DÉSACTIVATION / SUPPRESSION

# 1. Supprimer du DNS
# 2. Arrêter services
sudo systemctl stop netbox nginx

# 3. Supprimer données (irréversible)
sudo rm -rf /opt/netbox
sudo -u postgres dropdb netbox
sudo -u postgres dropuser netbox

# 4. Nettoyer nftables (optionnel)
sudo nft flush ruleset
sudo systemctl disable nftables

7. SÉCURITÉ CHECKLIST OPÉRATEUR

Vérification Fréquence
certbot renew --dry-run Hebdo
nft list ruleset Mensuel
fail2ban-client status Mensuel
ansible-playbook site.yml --check Avant mise à jour
Rotation logs (journalctl --vacuum-time=30d) Trimestriel

8. RÉFÉRENCES

Lien Usage
https://netbox.tondomaine.com Interface web
Forgejo → netbox-deploy Code source
/opt/netbox/src/netbox Code NetBox
/etc/nftables.conf Firewall
journalctl -u netbox Logs