# Agent2_Ansible — Automatisation Ansible Agent spécialisé dans l'automatisation d'infrastructure via Ansible. Exécute des playbooks et commandes ad-hoc sur les machines du réseau local. ## Rôle - Exécution de playbooks Ansible sur les hôtes du réseau local - Commandes ad-hoc Ansible (ping, shell, apt, service, copy...) - Gestion de l'inventaire et collecte de facts - Déploiement de configurations sur plusieurs machines simultanément - File d'attente SQLite : aucune tâche perdue même en cas de pause ou de redémarrage - Rapporte les résultats à agent1 via MQTT --- ## Commandes de contrôle (via agent1) Envoyées par agent1 sur le topic `agents/agent2_ansible/control` : | Commande XMPP (à agent1) | Effet sur cet agent | |---|---| | `!agentOFF agent2_ansible` | Pause — tâches en attente conservées dans queue.db | | `!agentON agent2_ansible` | Reprise — traitement des tâches en attente | | `!agentsOFF` | Pause (avec tous les autres agents) | | `!agentsON` | Reprise (avec tous les autres agents) | ## Skills disponibles | Trigger | Description | |---|---| | `ANSIBLE: ` | Commande ansible ad-hoc | | `PLAYBOOK: [options]` | Exécution de playbook | | `EXEC: ` | Commande shell locale | | `SEARCH: ` | Recherche DuckDuckGo | | `READ: ` | Lecture de page web | | `REMEMBER: \| ` | Mémoire SQLite | | `RECALL: ` | Récupération mémoire | ## Exemples de tâches ``` ANSIBLE: all -m ping ANSIBLE: all -m shell -a "uptime" ANSIBLE: webservers -m apt -a "name=nginx state=present" --become ANSIBLE: all -m gather_facts PLAYBOOK: site.yml PLAYBOOK: deploy.yml --limit webservers --tags packages PLAYBOOK: update.yml --check ``` ## Inventaire Editer `/opt/agent2_ansible/ansible/inventory/hosts` pour déclarer les machines : ```ini [servers] srv1 ansible_host=192.168.7.10 ansible_user=root srv2 ansible_host=192.168.7.11 ansible_user=debian [workstations] pc1 ansible_host=192.168.7.50 ansible_user=sylvain [all:vars] ansible_python_interpreter=/usr/bin/python3 ``` ## Playbooks Placer les playbooks dans `/opt/agent2_ansible/ansible/playbooks/`. ## Déploiement via agent2_deploy (recommandé) ``` # Via XMPP avec sylvain@xmpp.ovh, contacter agent2_deploy : !deploy # Choisir agent2_ansible, puis suivre le guide ``` ## Déploiement manuel ```bash # Prérequis apt-get install -y python3 python3-pip python3-venv git ansible # Cloner et installer git clone https://git.piaf.im/sylvain/agent2_ansible.git /opt/agent2_ansible cd /opt/agent2_ansible python3 -m venv venv venv/bin/pip install slixmpp paho-mqtt requests ddgs beautifulsoup4 chromadb # Configurer nano config/config.json nano ansible/inventory/hosts # Service systemd cat > /etc/systemd/system/agent2_ansible.service << 'EOF' [Unit] Description=Agent2 Ansible After=network.target mosquitto.service Wants=mosquitto.service [Service] Type=simple WorkingDirectory=/opt/agent2_ansible ExecStart=/usr/bin/python3 /opt/agent2_ansible/agent2_ansible.py Restart=always RestartSec=5 StandardOutput=journal StandardError=journal [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable agent2_ansible systemctl start agent2_ansible ``` ## Déploiement depuis le dépôt git (sur la machine cible) ```bash git clone https://git.piaf.im/sylvain/agent2_deploy.git /tmp/agent2_deploy python3 /tmp/agent2_deploy/deploy.py --local agent2_ansible ``` ## Configuration (`config/config.json`) ```json { "ollama_url" : "http://:11434/api/chat", "model" : "qwen3:8b", "xmpp_jid" : "agent2_ansible@xmpp.ovh", "xmpp_pass" : "", "admin_jid" : "sylvain@xmpp.ovh", "mqtt_host" : "", "mqtt_port" : 1883, "mqtt_client_id" : "agent2_ansible", "mqtt_inbox" : "agents/agent2_ansible/inbox", "mqtt_outbox" : "agents/agent1/inbox" } ``` ## Logs ```bash journalctl -u agent2_ansible -f ```