40 lines
1.8 KiB
YAML
40 lines
1.8 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
|
||
|
||
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 (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"
|
||
|
||
# -------------------------------------------------------
|
||
# Étape 3 – Uploader le fichier vers le serveur SFTP
|
||
# -------------------------------------------------------
|
||
- name: Rapatrier le fichier vers AWX
|
||
ansible.builtin.fetch:
|
||
src: "/tmp/config_{{ inventory_hostname }}.txt"
|
||
dest: "/var/collected/"
|
||
flat: yes |