ansible: création du playbook fail2ban & install.sh
This commit is contained in:
parent
ac037d05e1
commit
2ff8064703
43
ansible/install_fail2ban.sh
Executable file
43
ansible/install_fail2ban.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Demander les informations avec Zenity
|
||||||
|
USER_INPUT=$(zenity --forms --title="Configuration Fail2ban" \
|
||||||
|
--text="Remplissez les informations pour l'installation" \
|
||||||
|
--add-entry="Adresse IP du serveur" \
|
||||||
|
--add-entry="Utilisateur SSH" \
|
||||||
|
--add-entry="Mot de passe SSH" \
|
||||||
|
--add-entry="Port SSH" \
|
||||||
|
--add-entry="Webhook Mattermost" \
|
||||||
|
--separator=",")
|
||||||
|
|
||||||
|
# Vérifier si l'utilisateur a annulé
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Opération annulée."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extraire les valeurs
|
||||||
|
IP_SERVER=$(echo "$USER_INPUT" | cut -d',' -f1)
|
||||||
|
SSH_USER=$(echo "$USER_INPUT" | cut -d',' -f2)
|
||||||
|
SSH_PASS=$(echo "$USER_INPUT" | cut -d',' -f3)
|
||||||
|
SSH_PORT=$(echo "$USER_INPUT" | cut -d',' -f4)
|
||||||
|
MATTERMOST_WEBHOOK=$(echo "$USER_INPUT" | cut -d',' -f5)
|
||||||
|
|
||||||
|
# Vérifier que toutes les valeurs sont renseignées
|
||||||
|
if [[ -z "$IP_SERVER" || -z "$SSH_USER" || -z "$SSH_PASS" || -z "$SSH_PORT" || -z "$MATTERMOST_WEBHOOK" ]]; then
|
||||||
|
zenity --error --text="Toutes les informations doivent être remplies !" --width=300
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Générer un fichier d'inventaire dynamique
|
||||||
|
cat > inventory.ini <<EOL
|
||||||
|
[servers]
|
||||||
|
$IP_SERVER ansible_host=$IP_SERVER ansible_user=$SSH_USER ansible_password=$SSH_PASS ansible_port=$SSH_PORT ansible_become_password=$SSH_PASS
|
||||||
|
EOL
|
||||||
|
|
||||||
|
# Lancer le playbook Ansible avec les variables dynamiques
|
||||||
|
ansible-playbook -i inventory.ini playbooks/fail2ban.yml --extra-vars "ssh_port=$SSH_PORT mattermost_webhook=$MATTERMOST_WEBHOOK"
|
||||||
|
|
||||||
|
# Informer l'utilisateur que l'installation est terminée
|
||||||
|
zenity --info --text="Fail2ban a été installé et configuré sur $IP_SERVER !" --width=300
|
||||||
|
|
||||||
2
ansible/inventory.ini
Normal file
2
ansible/inventory.ini
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[servers]
|
||||||
|
192.168.1.78 ansible_host=192.168.1.78 ansible_user=smauro ansible_password=)_:&o=Idf=W}Guv4Tb(U[v<O ansible_port=22 ansible_become_password=)_:&o=Idf=W}Guv4Tb(U[v<O
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user