From 50e00e1009f20b0fc451376ef10b8ea2358a3597 Mon Sep 17 00:00:00 2001 From: "stephane.david" Date: Sat, 11 Jul 2026 14:21:49 +0200 Subject: [PATCH] Corrected error --- get_network_config.yml | 92 +++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/get_network_config.yml b/get_network_config.yml index 64fe710..1cb1bdd 100644 --- a/get_network_config.yml +++ b/get_network_config.yml @@ -1,60 +1,60 @@ --- # Playbook Ansible : Récupérer la config réseau + DNS, écrire dans un fichier local, puis SFTP -name: Collecte configuration réseau et DNS et upload SFTP +- name: Collecte configuration réseau et DNS et upload SFTP -vars: + vars: # Configuration du serveur SFTP distant (à adapter) - sftp_host: "linuxdev.maison" - sftp_user: "thedarty" - sftp_pass: "St&ph@ne10Nove.@1976" # ou utiliser un secret Ansible Vault - sftp_remote_dir: "/home/thedarty/deploy/" + sftp_host: "linuxdev.maison" + sftp_user: "thedarty" + sftp_pass: "St&ph@ne10Nove.@1976" # ou utiliser un secret Ansible Vault + sftp_remote_dir: "/home/thedarty/deploy/" -hosts: all + hosts: all -tasks: + tasks: # ------------------------------------------------------- # Étape 1 – Récupérer les infos réseau ET DNS du serveur cible # ------------------------------------------------------- - - name: Collecter la configuration réseau et DNS - shell: | - echo "=== Configuration réseau de {{ inventory_hostname }} ===" > /tmp/config_{{ inventory_hostname }}.txt - hostname >> /tmp/config_{{ inventory_hostname }}.txt - echo "" >> /tmp/config_{{ inventory_hostname }}.txt + - name: Collecter la configuration réseau et DNS + shell: | + echo "=== Configuration réseau de {{ inventory_hostname }} ===" > /tmp/config_{{ inventory_hostname }}.txt + hostname >> /tmp/config_{{ inventory_hostname }}.txt + echo "" >> /tmp/config_{{ inventory_hostname }}.txt - # --- Réseau --- - ip -4 addr show >> /tmp/config_{{ inventory_hostname }}.txt - echo "" >> /tmp/config_{{ inventory_hostname }}.txt - cat /etc/hostname >> /tmp/config_{{ inventory_hostname }}.txt - echo "" >> /tmp/config_{{ inventory_hostname }}.txt - ip route show >> /tmp/config_{{ inventory_hostname }}.txt + # --- Réseau --- + ip -4 addr show >> /tmp/config_{{ inventory_hostname }}.txt + echo "" >> /tmp/config_{{ inventory_hostname }}.txt + cat /etc/hostname >> /tmp/config_{{ inventory_hostname }}.txt + echo "" >> /tmp/config_{{ inventory_hostname }}.txt + ip route show >> /tmp/config_{{ inventory_hostname }}.txt - # --- DNS (resolv.conf + systemd-resolved) --- - echo "=== Configuration DNS ===" >> /tmp/config_{{ inventory_hostname }}.txt - cat /etc/resolv.conf >> /tmp/config_{{ inventory_hostname }}.txt - echo "" >> /tmp/config_{{ inventory_hostname }}.txt - resolvectl status >> /tmp/config_{{ inventory_hostname }}.txt 2>&1 || true + # --- DNS (resolv.conf + systemd-resolved) --- + echo "=== Configuration DNS ===" >> /tmp/config_{{ inventory_hostname }}.txt + cat /etc/resolv.conf >> /tmp/config_{{ inventory_hostname }}.txt + echo "" >> /tmp/config_{{ inventory_hostname }}.txt + resolvectl status >> /tmp/config_{{ inventory_hostname }}.txt 2>&1 || true - args: - creates: "/tmp/config_{{ inventory_hostname }}.txt" + args: + creates: "/tmp/config_{{ inventory_hostname }}.txt" - # ------------------------------------------------------- - # Étape 2 – (optionnel) Copier le fichier dans un dossier - # dédié pour faciliter la gestion des fichiers - # ------------------------------------------------------- - - name: Placer les fichiers de config dans /var/collected/ - synchronize: - src: "/tmp/config_{{ inventory_hostname }}.txt" - dest: "/var/collected/{{ inventory_hostname }}.txt" + # ------------------------------------------------------- + # Étape 2 – (optionnel) Copier le fichier dans un dossier + # dédié pour faciliter la gestion des fichiers + # ------------------------------------------------------- + - name: Placer les fichiers de config dans /var/collected/ + synchronize: + src: "/tmp/config_{{ inventory_hostname }}.txt" + dest: "/var/collected/{{ inventory_hostname }}.txt" - # ------------------------------------------------------- - # Étape 3 – Uploader le fichier vers le serveur SFTP - # ------------------------------------------------------- - - name: Upload du fichier de config réseau et DNS vers le serveur SFTP - sftp: - host: "{{ sftp_host }}" - username: "{{ sftp_user }}" - password: "{{ sftp_pass }}" - remote_src: yes - mode: "0644" - in_path: "/var/collected/{{ inventory_hostname }}.txt" - remote_dir: "{{ sftp_remote_dir }}" \ No newline at end of file + # ------------------------------------------------------- + # Étape 3 – Uploader le fichier vers le serveur SFTP + # ------------------------------------------------------- + - name: Upload du fichier de config réseau et DNS vers le serveur SFTP + sftp: + host: "{{ sftp_host }}" + username: "{{ sftp_user }}" + password: "{{ sftp_pass }}" + remote_src: yes + mode: "0644" + in_path: "/var/collected/{{ inventory_hostname }}.txt" + remote_dir: "{{ sftp_remote_dir }}" \ No newline at end of file