first revision

main
morepudding 3 months ago
commit 6bc41e657b

1
.gitignore vendored

@ -0,0 +1 @@
.venv

@ -0,0 +1,37 @@
# Projet Ansible - Installation Nginx sur VPS
## Configuration
1. **Modifier l'inventory** : Éditez `inventory.yml` et remplacez `YOUR_VPS_IP_ADDRESS` par l'adresse IP de votre VPS
2. **Configurer l'accès SSH** :
- Assurez-vous d'avoir accès SSH à votre VPS
- Si vous utilisez une clé SSH, décommentez et configurez `ansible_ssh_private_key_file`
## Utilisation
### Tester la connexion
```bash
ansible all -m ping
```
### Exécuter le playbook
```bash
ansible-playbook playbook.yml
```
### Exécuter en mode vérification (dry-run)
```bash
ansible-playbook playbook.yml --check
```
### Exécuter avec verbosité
```bash
ansible-playbook playbook.yml -v
```
## Structure du projet
- `ansible.cfg` : Configuration Ansible
- `inventory.yml` : Inventaire des serveurs au format YAML
- `playbook.yml` : Playbook d'installation de Nginx

@ -0,0 +1,11 @@
[defaults]
inventory = inventory.yml
host_key_checking = False
remote_user = root
retry_files_enabled = False
[privilege_escalation]
become = True
become_method = sudo
become_user = root
become_ask_pass = False

@ -0,0 +1,8 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACD8oPnRrBM3l7Iryjr2JjOl5ansc6isAPqIdrqM78X38gAAAKjKcKjqynCo
6gAAAAtzc2gtZWQyNTUxOQAAACD8oPnRrBM3l7Iryjr2JjOl5ansc6isAPqIdrqM78X38g
AAAEAxOMEMLKQ09q1641Hua7WSzgF8vRvx89EDEA3zKIiyjvyg+dGsEzeXsivKOvYmM6Xl
qexzqKwA+oh2uozvxffyAAAAJG1hY2Jvb2tATEFQVE9QLTNIQlVNSUpLLk5leHRHZW4uQ2
VzaQE=
-----END OPENSSH PRIVATE KEY-----

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPyg+dGsEzeXsivKOvYmM6XlqexzqKwA+oh2uozvxffy macbook@LAPTOP-3HBUMIJK.NextGen.Cesi

@ -0,0 +1,51 @@
#!/bin/bash
# Script d'installation du projet Ansible
set -e
echo "================================================"
echo "Installation du projet Ansible - Nginx sur VPS"
echo "================================================"
echo ""
# Vérifier si Python3 est installé
if ! command -v python3 &> /dev/null; then
echo "❌ Python3 n'est pas installé. Veuillez l'installer d'abord."
exit 1
fi
echo "✅ Python3 est installé"
# Créer un environnement virtuel s'il n'existe pas
if [ ! -d ".venv" ]; then
echo "📦 Création de l'environnement virtuel..."
python3 -m venv .venv
echo "✅ Environnement virtuel créé"
else
echo "✅ Environnement virtuel existe déjà"
fi
# Activer l'environnement virtuel
echo "🔧 Activation de l'environnement virtuel..."
source .venv/bin/activate
# Mettre à jour pip
echo "⬆️ Mise à jour de pip..."
pip install --upgrade pip > /dev/null 2>&1
# Installer les dépendances
echo "📥 Installation d'Ansible et des dépendances..."
pip install -r requirements.txt
echo ""
echo "✅ Installation terminée avec succès!"
echo ""
echo "================================================"
echo "Prochaines étapes:"
echo "================================================"
echo "1. Éditez 'inventory.yml' et configurez l'IP de votre VPS"
echo "2. Activez l'environnement virtuel : source .venv/bin/activate"
echo "3. Testez la connexion : ansible all -m ping"
echo "4. Lancez le script : ./run.sh"
echo ""

@ -0,0 +1,11 @@
---
all:
children:
webservers:
hosts:
vps1:
ansible_host: defder.fr
ansible_user: root
ansible_port: 22
ansible_ssh_private_key_file: ./defderkey

@ -0,0 +1,67 @@
---
- name: Installer et configurer Nginx sur VPS Ubuntu
hosts: webservers
become: yes
tasks:
- name: Mettre à jour le cache apt
apt:
update_cache: yes
cache_valid_time: 3600
- name: Installer Nginx
apt:
name: nginx
state: present
- name: S'assurer qu'UFW est installé
apt:
name: ufw
state: present
- name: Autoriser le trafic SSH dans le firewall (UFW)
ufw:
rule: allow
port: '22'
proto: tcp
- name: Autoriser le trafic HTTP dans le firewall (UFW)
ufw:
rule: allow
port: '80'
proto: tcp
- name: Autoriser le trafic HTTPS dans le firewall (UFW)
ufw:
rule: allow
port: '443'
proto: tcp
- name: Activer UFW(uncomplicated firewall)
ufw:
state: enabled
- name: Démarrer et activer Nginx
systemd:
name: nginx
state: started
enabled: yes
- name: Vérifier que Nginx est en cours d'exécution
service:
name: nginx
state: started
register: nginx_status
- name: Afficher le statut de Nginx
debug:
msg: "Nginx est installé et en cours d'exécution"
- name: Récupérer l'IP du serveur
command: hostname -I
register: server_ip
changed_when: false
- name: Afficher l'URL d'accès
debug:
msg: "Nginx est accessible à l'adresse : http://{{ server_ip.stdout.split()[0] }}"

@ -0,0 +1 @@
ansible>=2.9

@ -0,0 +1 @@
ansible-playbook -i inventory.yml --private-key defderkey playbook.yml
Loading…
Cancel
Save