Compare commits
10 Commits
7436825ae1
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dab7161176 | |||
| 4513807824 | |||
| 2b342d6e47 | |||
| 5c8cddbc17 | |||
| 7dde56012f | |||
| 0def8bc7bd | |||
| a1457b97ea | |||
| 69b4054b08 | |||
| 61bf4e3111 | |||
| 89a8d3c508 |
@@ -0,0 +1,98 @@
|
||||
---
|
||||
- name: Installer Docker - Méthode complète
|
||||
hosts: all
|
||||
become: yes
|
||||
|
||||
tasks:
|
||||
# Vérification préalable
|
||||
- name: Vérifier si Docker est déjà installé
|
||||
command: docker --version
|
||||
register: docker_check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Docker déjà présent
|
||||
debug:
|
||||
msg: "✓ Docker déjà installé : {{ docker_check.stdout }}"
|
||||
when: docker_check.rc == 0
|
||||
|
||||
- name: Poursuivre l'installation
|
||||
debug:
|
||||
msg: "Docker non détecté, installation en cours..."
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 1
|
||||
- name: sudo apt update
|
||||
apt:
|
||||
update_cache: yes
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 2
|
||||
- name: sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
|
||||
apt:
|
||||
name:
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg
|
||||
- lsb-release
|
||||
state: present
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 3
|
||||
- name: Créer le dossier /etc/apt/keyrings
|
||||
file:
|
||||
path: /etc/apt/keyrings
|
||||
state: directory
|
||||
mode: '0755'
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 4
|
||||
- name: curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
shell: curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
args:
|
||||
creates: /etc/apt/keyrings/docker.gpg
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 5
|
||||
- name: chmod a+r /etc/apt/keyrings/docker.gpg
|
||||
file:
|
||||
path: /etc/apt/keyrings/docker.gpg
|
||||
mode: 'a+r'
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 6
|
||||
- name: Ajouter le dépôt Docker
|
||||
shell: |
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
args:
|
||||
creates: /etc/apt/sources.list.d/docker.list
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 7
|
||||
- name: sudo apt update (après ajout du dépôt)
|
||||
apt:
|
||||
update_cache: yes
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Étape 8
|
||||
- name: sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
apt:
|
||||
name:
|
||||
- docker-ce
|
||||
- docker-ce-cli
|
||||
- containerd.io
|
||||
- docker-buildx-plugin
|
||||
- docker-compose-plugin
|
||||
state: present
|
||||
when: docker_check.rc != 0
|
||||
|
||||
# Vérification finale
|
||||
- name: Vérifier que Docker fonctionne
|
||||
command: docker --version
|
||||
register: docker_ver
|
||||
changed_when: false
|
||||
|
||||
- name: Résultat final
|
||||
debug:
|
||||
msg: "✓ Docker installé et opérationnel : {{ docker_ver.stdout }}"
|
||||
@@ -0,0 +1,63 @@
|
||||
---
|
||||
- name: Post-installation Debian
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: "=== ÉTAPE 1 : Mise à jour complète du système ==="
|
||||
debug:
|
||||
msg: "Mise à jour d'apt et upgrade complet..."
|
||||
|
||||
- name: Mettre à jour le cache APT
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: Upgrade complet (dist-upgrade)
|
||||
apt:
|
||||
upgrade: dist
|
||||
autoremove: yes
|
||||
autoclean: yes
|
||||
|
||||
- name: "=== ÉTAPE 2 : Désactivation IPv6 ==="
|
||||
debug:
|
||||
msg: "Désactivation d'IPv6..."
|
||||
|
||||
- name: Désactiver IPv6 via sysctl
|
||||
sysctl:
|
||||
name: "{{ item }}"
|
||||
value: "1"
|
||||
state: present
|
||||
reload: yes
|
||||
sysctl_file: /etc/sysctl.d/99-disable-ipv6.conf
|
||||
loop:
|
||||
- net.ipv6.conf.all.disable_ipv6
|
||||
- net.ipv6.conf.default.disable_ipv6
|
||||
- net.ipv6.conf.lo.disable_ipv6
|
||||
|
||||
- name: Appliquer les changements sysctl immédiatement
|
||||
command: sysctl -p /etc/sysctl.d/99-disable-ipv6.conf
|
||||
changed_when: false
|
||||
|
||||
- name: Vérifier que IPv6 est bien désactivé
|
||||
shell: cat /proc/sys/net/ipv6/conf/all/disable_ipv6
|
||||
register: ipv6_status
|
||||
changed_when: false
|
||||
|
||||
- name: "=== RÉSUMÉ ==="
|
||||
debug:
|
||||
msg:
|
||||
- "✓ Système mis à jour"
|
||||
- "✓ IPv6 désactivé (valeur: {{ ipv6_status.stdout }})"
|
||||
- "Note: Un redémarrage peut être nécessaire pour certains services"
|
||||
|
||||
- name: Vérifier si un redémarrage est nécessaire
|
||||
stat:
|
||||
path: /var/run/reboot-required
|
||||
register: reboot_required
|
||||
|
||||
- name: Avertissement redémarrage
|
||||
debug:
|
||||
msg: "⚠️ ATTENTION : Un redémarrage est nécessaire"
|
||||
when: reboot_required.stat.exists
|
||||
@@ -0,0 +1,340 @@
|
||||
---
|
||||
- name: Personnalisation du bash pour toutes les VMs de l'inventaire
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
vars:
|
||||
bash_config_version: "1.0"
|
||||
|
||||
tasks:
|
||||
- name: Afficher les informations de l'hôte
|
||||
debug:
|
||||
msg: "Configuration de {{ ansible_hostname }} ({{ ansible_distribution }} {{ ansible_distribution_version }})"
|
||||
|
||||
- name: Créer le répertoire profile.d si nécessaire
|
||||
file:
|
||||
path: /etc/profile.d
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Déployer la configuration bash personnalisée globale
|
||||
copy:
|
||||
dest: /etc/profile.d/custom_bash.sh
|
||||
mode: '0644'
|
||||
content: |
|
||||
# ============================================
|
||||
# Configuration bash personnalisée - v{{ bash_config_version }}
|
||||
# Déployé par Ansible via Semaphore
|
||||
# Hôte: {{ ansible_hostname }}
|
||||
# Date: {{ ansible_date_time.iso8601 }}
|
||||
# ============================================
|
||||
|
||||
# Prompt coloré avec utilisateur, hôte et chemin
|
||||
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||
|
||||
# Pour root, prompt en rouge
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
export PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]# '
|
||||
fi
|
||||
|
||||
# ============================================
|
||||
# Configuration de l'historique
|
||||
# ============================================
|
||||
export HISTSIZE=10000
|
||||
export HISTFILESIZE=20000
|
||||
export HISTCONTROL=ignoredups:erasedups
|
||||
export HISTTIMEFORMAT="%d/%m/%Y %H:%M:%S "
|
||||
|
||||
# Ajouter immédiatement les commandes à l'historique
|
||||
shopt -s histappend
|
||||
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
|
||||
|
||||
# ============================================
|
||||
# Alias de navigation
|
||||
# ============================================
|
||||
alias ..='cd ..'
|
||||
alias ...='cd ../..'
|
||||
alias ....='cd ../../..'
|
||||
alias .....='cd ../../../..'
|
||||
|
||||
# ============================================
|
||||
# Alias ls avec couleurs
|
||||
# ============================================
|
||||
alias ls='ls --color=auto'
|
||||
alias ll='ls -lah --color=auto'
|
||||
alias la='ls -A --color=auto'
|
||||
alias l='ls -CF --color=auto'
|
||||
alias lsd='ls -d */ --color=auto'
|
||||
|
||||
# ============================================
|
||||
# Alias grep avec couleurs
|
||||
# ============================================
|
||||
alias grep='grep --color=auto'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
|
||||
# ============================================
|
||||
# Alias système
|
||||
# ============================================
|
||||
alias df='df -h'
|
||||
alias du='du -h'
|
||||
alias free='free -h'
|
||||
alias top='htop 2>/dev/null || top'
|
||||
alias ps='ps auxf'
|
||||
alias psg='ps aux | grep -v grep | grep -i -e VSZ -e'
|
||||
alias meminfo='free -h -l -t'
|
||||
alias cpuinfo='lscpu'
|
||||
|
||||
# ============================================
|
||||
# Alias réseau
|
||||
# ============================================
|
||||
alias ports='netstat -tulanp'
|
||||
alias listening='netstat -tulanp | grep LISTEN'
|
||||
alias myip='curl -s ifconfig.me && echo'
|
||||
alias ping='ping -c 5'
|
||||
alias pingg='ping google.com -c 5'
|
||||
|
||||
# ============================================
|
||||
# Alias Git (utile avec Gitea)
|
||||
# ============================================
|
||||
alias gs='git status'
|
||||
alias ga='git add'
|
||||
alias gaa='git add --all'
|
||||
alias gc='git commit'
|
||||
alias gcm='git commit -m'
|
||||
alias gp='git push'
|
||||
alias gpl='git pull'
|
||||
alias gl='git log --oneline --graph --decorate --all'
|
||||
alias gd='git diff'
|
||||
alias gb='git branch'
|
||||
alias gco='git checkout'
|
||||
alias gclone='git clone'
|
||||
|
||||
# ============================================
|
||||
# Alias Docker (si disponible)
|
||||
# ============================================
|
||||
alias dps='docker ps'
|
||||
alias dpsa='docker ps -a'
|
||||
alias di='docker images'
|
||||
alias dex='docker exec -it'
|
||||
alias dlog='docker logs -f'
|
||||
alias dstop='docker stop $(docker ps -q)'
|
||||
alias drm='docker rm $(docker ps -aq)'
|
||||
alias drmi='docker rmi $(docker images -q)'
|
||||
|
||||
# ============================================
|
||||
# Alias de sécurité
|
||||
# ============================================
|
||||
alias rm='rm -i'
|
||||
alias cp='cp -i'
|
||||
alias mv='mv -i'
|
||||
alias ln='ln -i'
|
||||
|
||||
# ============================================
|
||||
# Alias Rsync
|
||||
# ============================================
|
||||
alias rsync-copy='rsync -avz --progress'
|
||||
alias rsync-move='rsync -avz --progress --remove-source-files'
|
||||
alias rsync-update='rsync -avzu --progress'
|
||||
alias rsync-sync='rsync -avzu --delete --progress'
|
||||
|
||||
# ============================================
|
||||
# Alias de date et heure
|
||||
# ============================================
|
||||
alias now='date +"%d-%m-%Y %T"'
|
||||
alias nowdate='date +"%d-%m-%Y"'
|
||||
alias nowtime='date +"%T"'
|
||||
|
||||
# ============================================
|
||||
# Alias journalctl (systemd logs)
|
||||
# ============================================
|
||||
alias jctl='journalctl -xe'
|
||||
alias jctlf='journalctl -f'
|
||||
alias jctlu='journalctl -u'
|
||||
|
||||
# ============================================
|
||||
# Fonctions utiles
|
||||
# ============================================
|
||||
|
||||
# Créer et entrer dans un répertoire
|
||||
mkcd() {
|
||||
mkdir -p "$1" && cd "$1"
|
||||
}
|
||||
|
||||
# Extraction intelligente d'archives
|
||||
extract() {
|
||||
if [ -f "$1" ]; then
|
||||
case "$1" in
|
||||
*.tar.bz2) tar xjf "$1" ;;
|
||||
*.tar.gz) tar xzf "$1" ;;
|
||||
*.tar.xz) tar xJf "$1" ;;
|
||||
*.bz2) bunzip2 "$1" ;;
|
||||
*.rar) unrar x "$1" ;;
|
||||
*.gz) gunzip "$1" ;;
|
||||
*.tar) tar xf "$1" ;;
|
||||
*.tbz2) tar xjf "$1" ;;
|
||||
*.tgz) tar xzf "$1" ;;
|
||||
*.zip) unzip "$1" ;;
|
||||
*.Z) uncompress "$1" ;;
|
||||
*.7z) 7z x "$1" ;;
|
||||
*) echo "'$1' ne peut pas être extrait avec cette fonction" ;;
|
||||
esac
|
||||
else
|
||||
echo "'$1' n'est pas un fichier valide"
|
||||
fi
|
||||
}
|
||||
|
||||
# Trouver les fichiers les plus volumineux
|
||||
bigfiles() {
|
||||
du -h "$1" 2>/dev/null | sort -rh | head -n ${2:-10}
|
||||
}
|
||||
|
||||
# Backup rapide d'un fichier
|
||||
backup() {
|
||||
cp "$1" "$1.backup-$(date +%Y%m%d-%H%M%S)"
|
||||
}
|
||||
|
||||
# Recherche rapide de fichiers
|
||||
ff() {
|
||||
find . -type f -iname "*$1*"
|
||||
}
|
||||
|
||||
# Recherche rapide de répertoires
|
||||
fd() {
|
||||
find . -type d -iname "*$1*"
|
||||
}
|
||||
|
||||
# ============================================
|
||||
# Variables d'environnement
|
||||
# ============================================
|
||||
export EDITOR=nano
|
||||
export VISUAL=nano
|
||||
export PAGER=less
|
||||
|
||||
# Configuration de less
|
||||
export LESS='-R -M -i'
|
||||
export LESSHISTFILE=-
|
||||
|
||||
# Couleurs pour man pages
|
||||
export LESS_TERMCAP_mb=$'\e[1;32m'
|
||||
export LESS_TERMCAP_md=$'\e[1;32m'
|
||||
export LESS_TERMCAP_me=$'\e[0m'
|
||||
export LESS_TERMCAP_se=$'\e[0m'
|
||||
export LESS_TERMCAP_so=$'\e[01;33m'
|
||||
export LESS_TERMCAP_ue=$'\e[0m'
|
||||
export LESS_TERMCAP_us=$'\e[1;4;31m'
|
||||
|
||||
# ============================================
|
||||
# Message de bienvenue
|
||||
# ============================================
|
||||
echo "🚀 Configuration bash personnalisée chargée (v{{ bash_config_version }})"
|
||||
echo "📝 Pour voir tous les alias: alias"
|
||||
echo "💡 Fonctions disponibles: mkcd, extract, bigfiles, backup, ff, fd"
|
||||
echo "📦 Rsync shortcuts: rsync-copy, rsync-move, rsync-update, rsync-sync"
|
||||
|
||||
- name: Créer le fichier nanorc personnalisé
|
||||
copy:
|
||||
dest: /etc/nanorc
|
||||
mode: '0644'
|
||||
content: |
|
||||
## Configuration Nano personnalisée
|
||||
set autoindent
|
||||
set tabsize 4
|
||||
set tabstospaces
|
||||
set linenumbers
|
||||
set mouse
|
||||
set smooth
|
||||
set softwrap
|
||||
set constantshow
|
||||
set casesensitive
|
||||
|
||||
## Activer la coloration syntaxique
|
||||
include "/usr/share/nano/*.nanorc"
|
||||
|
||||
## Raccourcis personnalisés
|
||||
bind ^S savefile main
|
||||
bind ^Q exit all
|
||||
bind ^F whereis main
|
||||
bind ^Z undo main
|
||||
bind ^Y redo main
|
||||
|
||||
- name: Appliquer les configurations pour les utilisateurs existants
|
||||
block:
|
||||
- name: Récupérer la liste des utilisateurs avec home directory
|
||||
shell: |
|
||||
getent passwd | awk -F: '$3 >= 1000 && $6 ~ /^\/home/ {print $1":"$6}'
|
||||
register: users_list
|
||||
changed_when: false
|
||||
|
||||
- name: Créer un lien symbolique vers la config globale pour chaque utilisateur
|
||||
file:
|
||||
src: /etc/profile.d/custom_bash.sh
|
||||
dest: "{{ item.split(':')[1] }}/.bash_custom"
|
||||
state: link
|
||||
owner: "{{ item.split(':')[0] }}"
|
||||
group: "{{ item.split(':')[0] }}"
|
||||
force: yes
|
||||
loop: "{{ users_list.stdout_lines }}"
|
||||
when: users_list.stdout_lines | length > 0
|
||||
|
||||
- name: Ajouter le sourcing de la config dans .bashrc des utilisateurs
|
||||
lineinfile:
|
||||
path: "{{ item.split(':')[1] }}/.bashrc"
|
||||
line: "[ -f ~/.bash_custom ] && source ~/.bash_custom"
|
||||
state: present
|
||||
create: yes
|
||||
owner: "{{ item.split(':')[0] }}"
|
||||
group: "{{ item.split(':')[0] }}"
|
||||
mode: '0644'
|
||||
loop: "{{ users_list.stdout_lines }}"
|
||||
when: users_list.stdout_lines | length > 0
|
||||
|
||||
- name: Installer des outils utiles (optionnel)
|
||||
package:
|
||||
name:
|
||||
- nano
|
||||
- htop
|
||||
- curl
|
||||
- wget
|
||||
- git
|
||||
- tree
|
||||
- ncdu
|
||||
- rsync
|
||||
- sudo
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Vérifier que la configuration est bien chargée
|
||||
shell: |
|
||||
bash -c 'source /etc/profile.d/custom_bash.sh && echo "Configuration OK"'
|
||||
register: config_check
|
||||
changed_when: false
|
||||
|
||||
- name: Afficher le résultat de la configuration
|
||||
debug:
|
||||
msg:
|
||||
- "✅ Configuration bash déployée avec succès sur {{ ansible_hostname }}"
|
||||
- "📦 Statut: {{ config_check.stdout }}"
|
||||
- "👤 Nombre d'utilisateurs configurés: {{ users_list.stdout_lines | length }}"
|
||||
|
||||
- name: Créer un fichier de rappel des commandes utiles
|
||||
copy:
|
||||
dest: /etc/motd
|
||||
mode: '0644'
|
||||
content: |
|
||||
╔═══════════════════════════════════════════════════════════╗
|
||||
║ Serveur: {{ ansible_hostname }}
|
||||
║ OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
|
||||
║ Configuration bash personnalisée active ✓
|
||||
╚═══════════════════════════════════════════════════════════╝
|
||||
|
||||
📌 Commandes utiles:
|
||||
• ll, la, l : Lister les fichiers
|
||||
• gs, ga, gc : Raccourcis Git
|
||||
• ports : Voir les ports ouverts
|
||||
• myip : Afficher l'IP publique
|
||||
• extract <file> : Extraire une archive
|
||||
• mkcd <dir> : Créer et entrer dans un dossier
|
||||
|
||||
💡 Tapez 'alias' pour voir tous les alias disponibles
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
- name: Ajouter clé SSH (garder mot de passe actif)
|
||||
hosts: all
|
||||
gather_facts: no
|
||||
vars:
|
||||
ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCdVtD/9JqTM4PHuobGzu1B+mwAK2Ov31VGfKQi38JLBFcpDnNt8WvmbOjj4igZzMkw5UsJQaGKEaCQXb9vFybP9ucfRuZNh7pvRGIMIUf/oFgRiA3bkad7sjnk1egXRmdJR5RawKuZ9u1iUkRuAuaomqF4dqLn5Ih3k/KfS0JLUbysKb36b0idwL0wbjfkpNvo4odcU8w+UiLXUrE6wt5xeLjw2y1R2VpmE6e4C9bIvM1Tyf8AJAcMbqGtp4Xfig7gO+4QIh6lRvcdT9Db7h/dK/bIC4B7SekTlZjfRPZlOR6yKGEPSae+Bux8OiFJ4Oyxg/HHoQPVg8t5kujf8a1TJbpGa6/kluxkk3oZBlA08X8dtlcVQ/gJqDUsf2n7ie5Aoq6JC5cvI8sqERBo1z05ksM8pk0uBh7B1+xEpvAUflvjKbGSuR352QTsXd6hm3UP5tP6P7sPp4o8xFTsry6r8ZJasPJqjIbc0pI7prMXfu4ITJ4iKrn1gpencxzQQIQJBU3pteLty+d2lKnok96knIs576uV52XjuZTep3CJVbg8mg/0xkHsedj1ZqD+kodjvsP7HFy/TtyHEdTx/35dLgYrZFAux1Yqmx9ncHRLcJgUIbQ2aLwA8oQb+O+LS5jLXbsjMexb5POH/Z+uLOYeFyuXdBLLTnGbRy4NE0HiEQ== semaphore@orchestre"
|
||||
|
||||
tasks:
|
||||
- name: Créer le répertoire .ssh
|
||||
file:
|
||||
path: /root/.ssh
|
||||
state: directory
|
||||
mode: '0700'
|
||||
|
||||
- name: Ajouter la clé publique
|
||||
authorized_key:
|
||||
user: root
|
||||
key: "{{ ssh_key }}"
|
||||
state: present
|
||||
|
||||
- name: Résultat
|
||||
debug:
|
||||
msg: "✓ Clé SSH ajoutée (mot de passe toujours actif)"
|
||||
@@ -0,0 +1,42 @@
|
||||
# playbook-rsyslog-to-graylog.yml
|
||||
---
|
||||
- name: Configure rsyslog to send logs to Graylog
|
||||
hosts: all
|
||||
become: yes
|
||||
vars:
|
||||
graylog_server: "192.168.123.16"
|
||||
graylog_port: "1514"
|
||||
|
||||
tasks:
|
||||
- name: Install rsyslog
|
||||
apt:
|
||||
name: rsyslog
|
||||
state: present
|
||||
update_cache: yes
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: Configure rsyslog to forward to Graylog
|
||||
copy:
|
||||
dest: /etc/rsyslog.d/90-graylog.conf
|
||||
content: |
|
||||
*.* @{{ graylog_server }}:{{ graylog_port }};RSYSLOG_SyslogProtocol23Format
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: restart rsyslog
|
||||
|
||||
- name: Ensure rsyslog is enabled and running
|
||||
systemd:
|
||||
name: rsyslog
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Send test log message
|
||||
command: logger "Test depuis {{ ansible_hostname }} - Configured by Ansible"
|
||||
changed_when: false
|
||||
|
||||
handlers:
|
||||
- name: restart rsyslog
|
||||
systemd:
|
||||
name: rsyslog
|
||||
state: restarted
|
||||
@@ -0,0 +1,89 @@
|
||||
---
|
||||
- name: Sécurité Simple - Réseau local libre, extérieur protégé
|
||||
hosts: all
|
||||
become: yes
|
||||
|
||||
tasks:
|
||||
- name: "=== Installation ==="
|
||||
apt:
|
||||
name:
|
||||
- ufw
|
||||
- fail2ban
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: "=== FIREWALL ==="
|
||||
debug:
|
||||
msg: "Configuration du firewall..."
|
||||
|
||||
- name: Règles par défaut UFW
|
||||
ufw:
|
||||
default: "{{ item.direction }}"
|
||||
direction: "{{ item.type }}"
|
||||
loop:
|
||||
- { direction: 'deny', type: 'incoming' }
|
||||
- { direction: 'allow', type: 'outgoing' }
|
||||
|
||||
- name: SSH autorisé (pour ne pas se bloquer)
|
||||
ufw:
|
||||
rule: allow
|
||||
port: '22'
|
||||
proto: tcp
|
||||
|
||||
- name: Tout le réseau local autorisé
|
||||
ufw:
|
||||
rule: allow
|
||||
from_ip: 192.168.123.0/24
|
||||
|
||||
- name: Activer UFW
|
||||
ufw:
|
||||
state: enabled
|
||||
|
||||
- name: "=== FAIL2BAN ==="
|
||||
debug:
|
||||
msg: "Configuration de Fail2ban..."
|
||||
|
||||
- name: Configuration Fail2ban simple
|
||||
copy:
|
||||
dest: /etc/fail2ban/jail.local
|
||||
content: |
|
||||
[DEFAULT]
|
||||
bantime = 3600
|
||||
findtime = 600
|
||||
maxretry = 5
|
||||
|
||||
[sshd]
|
||||
enabled = true
|
||||
port = ssh
|
||||
logpath = /var/log/auth.log
|
||||
maxretry = 3
|
||||
mode: '0644'
|
||||
|
||||
- name: Démarrer Fail2ban
|
||||
systemd:
|
||||
name: fail2ban
|
||||
state: restarted
|
||||
enabled: yes
|
||||
|
||||
- name: "=== VÉRIFICATION ==="
|
||||
command: ufw status
|
||||
register: fw_status
|
||||
changed_when: false
|
||||
|
||||
- name: Afficher config
|
||||
debug:
|
||||
var: fw_status.stdout_lines
|
||||
|
||||
- name: "=== RÉSUMÉ ==="
|
||||
debug:
|
||||
msg:
|
||||
- "================================================"
|
||||
- "✓ FIREWALL"
|
||||
- " Depuis 192.168.123.0/24 → TOUS LES PORTS OK"
|
||||
- " Depuis Internet → BLOQUÉ"
|
||||
- ""
|
||||
- "✓ FAIL2BAN"
|
||||
- " 3 tentatives SSH ratées → Ban 1h"
|
||||
- ""
|
||||
- "✓ VOUS ÊTES PROTÉGÉ !"
|
||||
- "================================================"
|
||||
Reference in New Issue
Block a user