Skip to content
Snippets Groups Projects
Commit 88fdadaf authored by ines's avatar ines
Browse files

add all, ok but not finished

parent e6193455
Branches
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ Le fichier *ansible.yml* est le playbook principal permettant d'exécuter la par ...@@ -13,6 +13,9 @@ Le fichier *ansible.yml* est le playbook principal permettant d'exécuter la par
Le dossier *captures* contient les captures d'écran prouvant la bonne réalisation de ce travail pratique Le dossier *captures* contient les captures d'écran prouvant la bonne réalisation de ce travail pratique
## Prérequis
## Fonctionnement / Commandes ## Fonctionnement / Commandes
Afin de créer le fichier de configuration du projet gns3, il faut exéctuer la commande suivante Afin de créer le fichier de configuration du projet gns3, il faut exéctuer la commande suivante
......
<!DOCTYPE html>
<html>
<head>
<title>Tp 3 - Ansible</title>
</head>
<body>
<h1>wellcome</h1>
<p>My IP address is {{ interfaces[inventory_hostname].wg_address }}</p>
</body>
</html>
server {
listen 10.0.0.1:80;
server_name H2;
allow 10.0.0.1/24;
deny all;
location / {
root /var/www/html;
index index.html;
}
}
\ No newline at end of file
[Interfaces]
PrivateKey = {{ interfaces[inventory_hostname].wg_private_key }}
Address = {{ interfaces[inventory_hostname].wg_address }}
ListenPort = {{ interfaces[inventory_hostname].listen_port }}
[Peer]
PublicKey = {{ interfaces[inventory_hostname].wg_public_key }}
AllowedIPs = {{ interfaces[inventory_hostname].wg_allowed_ips }}
Endpoint = {{ interfaces[inventory_hostname].wg_endpoint }}
\ No newline at end of file
...@@ -8,12 +8,26 @@ ...@@ -8,12 +8,26 @@
netmask: 255.255.255.0 netmask: 255.255.255.0
subnet: 3.0.0.0/24 subnet: 3.0.0.0/24
nexthop: 1.0.0.1 nexthop: 1.0.0.1
wg_endpoint: 10.0.0.3:51820
server_name: 10.0.0.3
listen_port: 51820
wg_address: 10.0.0.2/24
wg_allowed_ips: 10.0.0.0/24
wg_public_key: "derjgunZ8CXXghx7zzAcMfHULduvxrz3J2jbzlQ/eQg="
wg_private_key: "kE//aH71O9u/DFubv+KORitDAG5WzkJhjqkLfGAyUm0="
H2: H2:
eth0: eth0:
address: 3.0.0.3 address: 3.0.0.3
netmask: 255.255.255.0 netmask: 255.255.255.0
subnet: 1.0.0.0/24 subnet: 1.0.0.0/24
nexthop: 3.0.0.2 nexthop: 3.0.0.2
wg_endpoint: 10.0.0.3:51820
server_name: 10.0.0.3
listen_port: 51820
wg_address: 10.0.0.1/24
wg_allowed_ips: 10.0.0.0/24
wg_public_key: "b+/pkH6Jrjxvb/7VHOviIPo+UkMmg5KCCr/PXMwjURc="
wg_private_key: "MGU1UFaHd+jGpHLUcksVGdM915boQmsqNhAR43C282E="
R1: R1:
eth0: eth0:
address: 2.0.0.1 address: 2.0.0.1
...@@ -34,9 +48,10 @@ ...@@ -34,9 +48,10 @@
nexthop: 2.0.0.1 nexthop: 2.0.0.1
tasks: tasks:
- name: Print result # - name: Print result
debug: # debug:
msg: "{{ interfaces[inventory_hostname] }}" # msg: "{{ interfaces[inventory_hostname].server_name }}"
# when: inventory_hostname in groups['hotes']
- name: Restart interfaces routeurs - name: Restart interfaces routeurs
template: template:
...@@ -52,6 +67,7 @@ ...@@ -52,6 +67,7 @@
when: inventory_hostname in groups['hotes'] when: inventory_hostname in groups['hotes']
notify: restart networking notify: restart networking
# Tâche permettant d'avoir internet sur les hôtes
- name: Give internet to host - name: Give internet to host
ansible.builtin.shell: ansible.builtin.shell:
cmd: "dhclient -v mgmt0" cmd: "dhclient -v mgmt0"
...@@ -64,6 +80,7 @@ ...@@ -64,6 +80,7 @@
update_cache: yes update_cache: yes
when: inventory_hostname in groups['hotes'] when: inventory_hostname in groups['hotes']
# Installation de nginx
- name: Install nginx - name: Install nginx
ansible.builtin.apt: ansible.builtin.apt:
pkg: pkg:
...@@ -74,8 +91,50 @@ ...@@ -74,8 +91,50 @@
state: present state: present
when: inventory_hostname in groups['hotes'] when: inventory_hostname in groups['hotes']
- name: Configure the wireguard tunnel
template:
src: templates/wg0.conf.j2
dest: /etc/wireguard/wg0.conf
notify: Restart the wireguard tunnel
when: inventory_hostname in groups['hotes']
- name: Configure the web server with nginx
template:
src: templates/nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: Restart the web server
when: inventory_hostname == 'H2'
- name: Configurer la page web avec Nginx
template:
src: templates/index.html.j2
dest: /var/www/html/index.html
notify: Restart the web server
when: inventory_hostname == 'H2'
# - name: Check connectivity using curl
# shell: "curl 10.0.0.1"
# register: result
# ignore_errors: true
# when: inventory_hostname in groups['hotes']
# - name: Print result connectivity
# debug:
# msg: "{{ result.stdout_lines }}"
# when: inventory_hostname in groups['hotes']
handlers: handlers:
- name: restart networking - name: Restart networking
service: service:
name: networking name: networking
state: restarted state: restarted
- name: Restart the wireguard tunnel
systemd:
name: wg-quick@wg0.service
state: restarted
- name: Restart the web server
systemd:
name: nginx
state: restarted
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment