67 lines
2.9 KiB
YAML
67 lines
2.9 KiB
YAML
---
|
||
# 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
|
||
hosts: all
|
||
become: yes
|
||
|
||
vars:
|
||
nas_url: "https://dartydisk5.maison:5006" # ex: https://192.168.1.10:5006
|
||
nas_path: "/Datas/NetworkConfigs" # dossier WebDAV
|
||
nas_user: "stephane.david"
|
||
nas_pass: "St&ph@ne"
|
||
|
||
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
|
||
|
||
# --- 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 ---
|
||
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
|
||
|
||
# --- Netplan ---
|
||
echo "=== Configuration Netplan ===" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
|
||
if [ -d /etc/netplan ]; then
|
||
echo "Fichiers Netplan :" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
ls -1 /etc/netplan >> /tmp/config_{{ inventory_hostname }}.txt
|
||
echo "" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
|
||
for f in /etc/netplan/*.yaml; do
|
||
echo "--- $f ---" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
cat "$f" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
echo "" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
done
|
||
|
||
# netplan get (Ubuntu 22.04+)
|
||
if command -v netplan >/dev/null 2>&1; then
|
||
echo "=== netplan get ===" >> /tmp/config_{{ inventory_hostname }}.txt
|
||
netplan get >> /tmp/config_{{ inventory_hostname }}.txt 2>&1 || true
|
||
fi
|
||
else
|
||
echo "Netplan non présent sur ce système." >> /tmp/config_{{ inventory_hostname }}.txt
|
||
fi
|
||
|
||
args:
|
||
creates: "/tmp/config_{{ inventory_hostname }}.txt"
|
||
|
||
- name: Upload vers NAS via WebDAV
|
||
shell: |
|
||
curl -k -u '{{ nas_user }}:{{ nas_pass }}' \
|
||
-T /tmp/config_{{ inventory_hostname }}.txt \
|
||
"{{ nas_url }}{{ nas_path }}/config_{{ inventory_hostname }}.txt"
|
||
delegate_to: "{{ inventory_hostname }}" |