Corrected error
This commit is contained in:
+46
-46
@@ -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 }}"
|
||||
# -------------------------------------------------------
|
||||
# É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 }}"
|
||||
Reference in New Issue
Block a user