Skip to content
Snippets Groups Projects
Commit 4d3d1677 authored by leo.pellandi's avatar leo.pellandi
Browse files

last_version changed ip (demo)

parent d708536e
No related branches found
No related tags found
No related merge requests found
...@@ -47,13 +47,13 @@ ...@@ -47,13 +47,13 @@
vars: vars:
H1_interfaces: H1_interfaces:
- name: "eth0" - name: "eth0"
address: "1.0.0.3" address: "1.0.0.10"
netmask: "255.255.255.0" netmask: "255.255.255.0"
gateway: "1.0.0.1" gateway: "1.0.0.1"
H2_interfaces: H2_interfaces:
- name: "eth0" - name: "eth0"
address: "3.0.0.3" address: "3.0.0.10"
netmask: "255.255.255.0" netmask: "255.255.255.0"
gateway: "3.0.0.2" gateway: "3.0.0.2"
...@@ -74,6 +74,19 @@ ...@@ -74,6 +74,19 @@
loop: "{{ H2_interfaces }}" loop: "{{ H2_interfaces }}"
when: inventory_hostname == 'H2' 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: handlers:
- name: restart networking - name: restart networking
ansible.builtin.service: ansible.builtin.service:
......
- name: Configuration Wireguard et Nginx - name: Configuration Wireguard et Nginx
hosts: hosts hosts: hosts
vars_files:
- keys.yaml
vars: vars:
priv_key_H1: "GJXORDY3YAEn6iSKP90sPyiYQN1VWaTcjjS7vBquL0k=" privkey_H1: "{{ priv_key_H1 }}"
priv_key_H2: "MLPQU2YL6qpXj9ZGqgcn6XN0yMLR6Ly9R2Vo0KjjXH0=" privkey_H2: "{{ priv_key_H2 }}"
pub_key_H1: "uv7/gTFNszZOBoidTVgcoKR5f7iPrbpqWuz1gpvK5wU=" pubkey_H1: "{{ pub_key_H1 }}"
pub_key_H2: "ytSiRpbtlThJ6HAJ3XlL/hoa96iwkVsQLiv7Jp6ng2w=" pubkey_H2: "{{ pub_key_H2 }}"
ip_curl: 10.0.0.2 ip_curl: 10.0.0.2
tasks: tasks:
- name: Generate WireGuard configuration - name: Generate WireGuard configuration
...@@ -15,14 +18,14 @@ ...@@ -15,14 +18,14 @@
when: inventory_hostname == 'H1' or inventory_hostname == 'H2' when: inventory_hostname == 'H1' or inventory_hostname == 'H2'
- name: Start WireGuard tunnel - name: Start WireGuard tunnel
command: "systemctl start wg-quick@wg0" command: "systemctl restart wg-quick@wg0"
become: true become: true
when: inventory_hostname == 'H1' or inventory_hostname == 'H2' when: inventory_hostname == 'H1' or inventory_hostname == 'H2'
- name: Install Nginx configuration template - name: Install Nginx configuration template
template: template:
src: nginx.conf.j2 src: nginx.conf.j2
dest: "/etc/nginx/sites-available/default" dest: "/var/www/html/index.html"
when: inventory_hostname == 'H2' when: inventory_hostname == 'H2'
- name: Start Nginx service - name: Start Nginx service
......
$ANSIBLE_VAULT;1.1;AES256
37623430343232356336363762383862646166333539393666666432366361396162383666343433
3639396261613462663935626537326134333934623834360a663465643432313366616631353037
37313966356539643665653062356237386162373263346332356662653731303662393534326635
3430643931343038370a333839363664373230613636396630633761613663623464336430366165
39666361616466356564353737326437386430386265323531336332376634326263363935346335
35306232356633343165336234386261336564356366303963303866636430353834616332303937
66646331653637643566363765363130313337656136653766616566663464353063383162346638
33376166393031376661346466646538626461356433613963366663323631616630303637663566
36663134316130646433353465616465393535343566323864346562633631643236323837626138
39653932373532353062656432333661386636613165646466303938333431363139366166656466
37353837396262633336303961366537373534363033353461386635623037623363396438316337
38626562383932373666663466326363396434663065653362386265396530356164386336373235
30313263343964336137346238313537666530326664333937653034306635386632613338616339
66376631363138333165303931356238396665333436353533356138386135356461313936383034
63663636313737396432623164343239633936356336326130643035626566636162373530326365
33326138333738356537
server {
listen 80;
server_name 10.0.0.2;
location / { <!DOCTYPE html>
root /var/www/html; <html lang="en">
index index.html; <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>
# Fichier de configuration WireGuard généré par Ansible
[Interface] [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 %} Address = {% if inventory_hostname == 'H1' %}10.0.0.1/24{% else %}10.0.0.2/24{% endif %}
...@@ -9,12 +7,12 @@ ListenPort = 51890 ...@@ -9,12 +7,12 @@ ListenPort = 51890
{% if inventory_hostname == 'H2' %} {% if inventory_hostname == 'H2' %}
[Peer] [Peer]
PublicKey = {{ pub_key_H1 }} PublicKey = {{ pubkey_H1 }}
AllowedIPs = 0.0.0.0/0 AllowedIPs = 0.0.0.0/0
Endpoint = 1.0.0.3:51890 Endpoint = 1.0.0.10:51890
{% else %} {% else %}
[Peer] [Peer]
PublicKey = {{ pub_key_H2 }} PublicKey = {{ pubkey_H2 }}
AllowedIPs = 0.0.0.0/0 AllowedIPs = 0.0.0.0/0
Endpoint = 3.0.0.3:51890 Endpoint = 3.0.0.10:51890
{% endif %} {% endif %}
\ 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