diff --git a/ansible.yaml b/ansible.yaml index 4528586974a83393ec62e271a5f8ef38e63c410e..34d69feb18b009d6f7527f47a919ef10705a2b6b 100644 --- a/ansible.yaml +++ b/ansible.yaml @@ -47,13 +47,13 @@ vars: H1_interfaces: - name: "eth0" - address: "1.0.0.3" + address: "1.0.0.10" netmask: "255.255.255.0" gateway: "1.0.0.1" H2_interfaces: - name: "eth0" - address: "3.0.0.3" + address: "3.0.0.10" netmask: "255.255.255.0" gateway: "3.0.0.2" @@ -74,6 +74,19 @@ loop: "{{ H2_interfaces }}" when: inventory_hostname == 'H2' + - name: ping H1 -> H2 + shell: + cmd: "ping 3.0.0.10 -c 3" + executable: /bin/bash + register: ping_output + ignore_errors: true + when: inventory_hostname == 'H1' + + - name: Ping print + debug: + msg: "{{ ping_output.stdout }}" + when: inventory_hostname == 'H1' + handlers: - name: restart networking ansible.builtin.service: diff --git a/ansible_part2.yaml b/ansible_part2.yaml index f0085f8a5c2f5bebcf875f53af0db41d57662bf1..01d4d13a90878dee0ddb010a0cfc49b6d8ee054b 100644 --- a/ansible_part2.yaml +++ b/ansible_part2.yaml @@ -1,11 +1,14 @@ + - name: Configuration Wireguard et Nginx hosts: hosts + vars_files: + - keys.yaml vars: - priv_key_H1: "GJXORDY3YAEn6iSKP90sPyiYQN1VWaTcjjS7vBquL0k=" - priv_key_H2: "MLPQU2YL6qpXj9ZGqgcn6XN0yMLR6Ly9R2Vo0KjjXH0=" - pub_key_H1: "uv7/gTFNszZOBoidTVgcoKR5f7iPrbpqWuz1gpvK5wU=" - pub_key_H2: "ytSiRpbtlThJ6HAJ3XlL/hoa96iwkVsQLiv7Jp6ng2w=" + privkey_H1: "{{ priv_key_H1 }}" + privkey_H2: "{{ priv_key_H2 }}" + pubkey_H1: "{{ pub_key_H1 }}" + pubkey_H2: "{{ pub_key_H2 }}" ip_curl: 10.0.0.2 tasks: - name: Generate WireGuard configuration @@ -15,14 +18,14 @@ when: inventory_hostname == 'H1' or inventory_hostname == 'H2' - name: Start WireGuard tunnel - command: "systemctl start wg-quick@wg0" + command: "systemctl restart wg-quick@wg0" become: true when: inventory_hostname == 'H1' or inventory_hostname == 'H2' - name: Install Nginx configuration template template: src: nginx.conf.j2 - dest: "/etc/nginx/sites-available/default" + dest: "/var/www/html/index.html" when: inventory_hostname == 'H2' - name: Start Nginx service diff --git a/keys.yaml b/keys.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f5e91731c153b20c3b16bca5f62f26ec78091a85 --- /dev/null +++ b/keys.yaml @@ -0,0 +1,17 @@ +$ANSIBLE_VAULT;1.1;AES256 +37623430343232356336363762383862646166333539393666666432366361396162383666343433 +3639396261613462663935626537326134333934623834360a663465643432313366616631353037 +37313966356539643665653062356237386162373263346332356662653731303662393534326635 +3430643931343038370a333839363664373230613636396630633761613663623464336430366165 +39666361616466356564353737326437386430386265323531336332376634326263363935346335 +35306232356633343165336234386261336564356366303963303866636430353834616332303937 +66646331653637643566363765363130313337656136653766616566663464353063383162346638 +33376166393031376661346466646538626461356433613963366663323631616630303637663566 +36663134316130646433353465616465393535343566323864346562633631643236323837626138 +39653932373532353062656432333661386636613165646466303938333431363139366166656466 +37353837396262633336303961366537373534363033353461386635623037623363396438316337 +38626562383932373666663466326363396434663065653362386265396530356164386336373235 +30313263343964336137346238313537666530326664333937653034306635386632613338616339 +66376631363138333165303931356238396665333436353533356138386135356461313936383034 +63663636313737396432623164343239633936356336326130643035626566636162373530326365 +33326138333738356537 diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index c1d28ee675e9e53fb33f8c548473d152d01193fb..c314c946045ff7c7b3331211e2b4cad48cf9de19 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -1,9 +1,13 @@ -server { - listen 80; - server_name 10.0.0.2; - location / { - root /var/www/html; - index index.html; - } -} +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Bienvenue</title> +</head> +<body> + <h1>Bienvenue sur notre site web !</h1> + <p>Merci de visiter notre site. Nous sommes ravis de vous accueillir.</p> +</body> +</html> diff --git a/templates/wireguard.conf.j2 b/templates/wireguard.conf.j2 index c6325525697a02c1a5fcdf6a010757894d6bbfed..2ffe0f4519fbbde6acf25285d7f88a0e26be2718 100644 --- a/templates/wireguard.conf.j2 +++ b/templates/wireguard.conf.j2 @@ -1,7 +1,5 @@ -# Fichier de configuration WireGuard généré par Ansible - [Interface] -PrivateKey = {% if inventory_hostname == 'H1' %}{{ priv_key_H1 }}{% else %}{{ priv_key_H2 }}{% endif %} +PrivateKey = {% if inventory_hostname == 'H1' %}{{ privkey_H1 }}{% else %}{{ privkey_H2 }}{% endif %} Address = {% if inventory_hostname == 'H1' %}10.0.0.1/24{% else %}10.0.0.2/24{% endif %} @@ -9,12 +7,12 @@ ListenPort = 51890 {% if inventory_hostname == 'H2' %} [Peer] -PublicKey = {{ pub_key_H1 }} +PublicKey = {{ pubkey_H1 }} AllowedIPs = 0.0.0.0/0 -Endpoint = 1.0.0.3:51890 +Endpoint = 1.0.0.10:51890 {% else %} [Peer] -PublicKey = {{ pub_key_H2 }} +PublicKey = {{ pubkey_H2 }} AllowedIPs = 0.0.0.0/0 -Endpoint = 3.0.0.3:51890 +Endpoint = 3.0.0.10:51890 {% endif %} \ No newline at end of file