Corrected error

This commit is contained in:
2026-07-11 14:21:49 +02:00
parent a9a8cd8a06
commit 50e00e1009
+46 -46
View File
@@ -1,60 +1,60 @@
--- ---
# Playbook Ansible : Récupérer la config réseau + DNS, écrire dans un fichier local, puis SFTP # 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) # Configuration du serveur SFTP distant (à adapter)
sftp_host: "linuxdev.maison" sftp_host: "linuxdev.maison"
sftp_user: "thedarty" sftp_user: "thedarty"
sftp_pass: "St&ph@ne10Nove.@1976" # ou utiliser un secret Ansible Vault sftp_pass: "St&ph@ne10Nove.@1976" # ou utiliser un secret Ansible Vault
sftp_remote_dir: "/home/thedarty/deploy/" 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 # Étape 1 Récupérer les infos réseau ET DNS du serveur cible
# ------------------------------------------------------- # -------------------------------------------------------
- name: Collecter la configuration réseau et DNS - name: Collecter la configuration réseau et DNS
shell: | shell: |
echo "=== Configuration réseau de {{ inventory_hostname }} ===" > /tmp/config_{{ inventory_hostname }}.txt echo "=== Configuration réseau de {{ inventory_hostname }} ===" > /tmp/config_{{ inventory_hostname }}.txt
hostname >> /tmp/config_{{ inventory_hostname }}.txt hostname >> /tmp/config_{{ inventory_hostname }}.txt
echo "" >> /tmp/config_{{ inventory_hostname }}.txt echo "" >> /tmp/config_{{ inventory_hostname }}.txt
# --- Réseau --- # --- Réseau ---
ip -4 addr show >> /tmp/config_{{ inventory_hostname }}.txt ip -4 addr show >> /tmp/config_{{ inventory_hostname }}.txt
echo "" >> /tmp/config_{{ inventory_hostname }}.txt echo "" >> /tmp/config_{{ inventory_hostname }}.txt
cat /etc/hostname >> /tmp/config_{{ inventory_hostname }}.txt cat /etc/hostname >> /tmp/config_{{ inventory_hostname }}.txt
echo "" >> /tmp/config_{{ inventory_hostname }}.txt echo "" >> /tmp/config_{{ inventory_hostname }}.txt
ip route show >> /tmp/config_{{ inventory_hostname }}.txt ip route show >> /tmp/config_{{ inventory_hostname }}.txt
# --- DNS (resolv.conf + systemd-resolved) --- # --- DNS (resolv.conf + systemd-resolved) ---
echo "=== Configuration DNS ===" >> /tmp/config_{{ inventory_hostname }}.txt echo "=== Configuration DNS ===" >> /tmp/config_{{ inventory_hostname }}.txt
cat /etc/resolv.conf >> /tmp/config_{{ inventory_hostname }}.txt cat /etc/resolv.conf >> /tmp/config_{{ inventory_hostname }}.txt
echo "" >> /tmp/config_{{ inventory_hostname }}.txt echo "" >> /tmp/config_{{ inventory_hostname }}.txt
resolvectl status >> /tmp/config_{{ inventory_hostname }}.txt 2>&1 || true resolvectl status >> /tmp/config_{{ inventory_hostname }}.txt 2>&1 || true
args: args:
creates: "/tmp/config_{{ inventory_hostname }}.txt" creates: "/tmp/config_{{ inventory_hostname }}.txt"
# ------------------------------------------------------- # -------------------------------------------------------
# Étape 2 (optionnel) Copier le fichier dans un dossier # Étape 2 (optionnel) Copier le fichier dans un dossier
# dédié pour faciliter la gestion des fichiers # dédié pour faciliter la gestion des fichiers
# ------------------------------------------------------- # -------------------------------------------------------
- name: Placer les fichiers de config dans /var/collected/ - name: Placer les fichiers de config dans /var/collected/
synchronize: synchronize:
src: "/tmp/config_{{ inventory_hostname }}.txt" src: "/tmp/config_{{ inventory_hostname }}.txt"
dest: "/var/collected/{{ inventory_hostname }}.txt" dest: "/var/collected/{{ inventory_hostname }}.txt"
# ------------------------------------------------------- # -------------------------------------------------------
# Étape 3 Uploader le fichier vers le serveur SFTP # Étape 3 Uploader le fichier vers le serveur SFTP
# ------------------------------------------------------- # -------------------------------------------------------
- name: Upload du fichier de config réseau et DNS vers le serveur SFTP - name: Upload du fichier de config réseau et DNS vers le serveur SFTP
sftp: sftp:
host: "{{ sftp_host }}" host: "{{ sftp_host }}"
username: "{{ sftp_user }}" username: "{{ sftp_user }}"
password: "{{ sftp_pass }}" password: "{{ sftp_pass }}"
remote_src: yes remote_src: yes
mode: "0644" mode: "0644"
in_path: "/var/collected/{{ inventory_hostname }}.txt" in_path: "/var/collected/{{ inventory_hostname }}.txt"
remote_dir: "{{ sftp_remote_dir }}" remote_dir: "{{ sftp_remote_dir }}"