Skip to content
Snippets Groups Projects
Commit 3312477c authored by poulpe's avatar poulpe
Browse files

[Update+fix] Fix wireguard startup + fix nginx config

parent 856ea2d1
No related branches found
No related tags found
No related merge requests found
...@@ -63,8 +63,10 @@ ...@@ -63,8 +63,10 @@
cmd: "ip r add default nexthop via 10.0.2.2" cmd: "ip r add default nexthop via 10.0.2.2"
# check_mode: yes # check_mode: yes
- name: Install nginx and Wireguard - name: Install update for install other programs
ansible.builtin.apt: ansible.builtin.apt:
cache_valid_time: 86400
upgrade: yes
update_cache: yes update_cache: yes
# check_mode: yes # check_mode: yes
...@@ -75,6 +77,7 @@ ...@@ -75,6 +77,7 @@
- wireguard - wireguard
- wireguard-tools - wireguard-tools
- iptables - iptables
- curl
state: present state: present
# check_mode: yes # check_mode: yes
- name: Remove internet to host - name: Remove internet to host
...@@ -86,23 +89,36 @@ ...@@ -86,23 +89,36 @@
hosts: H2 hosts: H2
become: true become: true
tasks: tasks:
- name: Setup VPN Wireguard H2
ansible.builtin.template:
src: ./templates/wireguard_config_template_H2.j2
dest: /etc/wireguard/wg0.conf
mode: 0640
notify: wg-quick
- name: Setup page of nginx - name: Setup page of nginx
ansible.builtin.template: ansible.builtin.template:
src: ./templates/index_template.j2 src: ./templates/index_template.j2
dest: /var/www/index.html dest: /var/www/html/index.html
mode: 0640 mode: 0777
- name: Setup config of nginx - name: Setup config of nginx
ansible.builtin.template: ansible.builtin.template:
src: ./templates/nginx_config_template.j2 src: ./templates/nginx_config_template.j2
dest: /etc/nginx/sites-enabled/web_site dest: /etc/nginx/sites-available/default
mode: 0640 mode: 0640
notify: Restart nginx
- name: Setup VPN Wireguard H2 handlers:
ansible.builtin.template: - name: wg-quick
src: ./templates/wireguard_config_template_H2.j2 ansible.builtin.shell:
dest: /etc/wireguard/wg0.conf cmd: "wg-quick up wg0 2>/dev/null"
mode: 0640
- name: Restart nginx
ansible.builtin.service:
name: nginx
state: restarted
enabled: yes
- name: Setup index.html on H2 - name: Setup index.html on H2
hosts: H1 hosts: H1
...@@ -113,14 +129,38 @@ ...@@ -113,14 +129,38 @@
src: ./templates/wireguard_config_template_H1.j2 src: ./templates/wireguard_config_template_H1.j2
dest: /etc/wireguard/wg0.conf dest: /etc/wireguard/wg0.conf
mode: 0640 mode: 0640
notify: wg-quick
handlers:
- name: wg-quick
ansible.builtin.shell:
cmd: "wg-quick up wg0 2>/dev/null"
- name: Start wireguard for all hosts - name: Start wireguard for all hosts
hosts: hotes hosts: hotes
become: true become: true
tasks: tasks:
- name: Start wg-quick # - name: Start wg-quick
# ansible.builtin.shell:
# cmd: "wg-quick up wg0 2>/dev/null"
- name: Make curl to web server
ansible.builtin.shell: ansible.builtin.shell:
cmd: "wg-quick up wg0" cmd: "curl http://10.0.0.1:80/index.html > index.html"
- name: Test connectivity from H1 to H2
hosts: H1
tasks:
- name: Ping form H1 to H2
ansible.builtin.shell: "ping 10.0.0.1 -c 1"
- name: Check connectivity using curl
shell: "curl 10.0.0.1"
register: result
ignore_errors: true
- name: Print result
debug:
msg: "Connectivity test {{ 'succeeded' if result.rc == 0 else 'failed' }}."
... ...
\ No newline at end of file
server { server {
listen 10.0.0.0:80; listen 10.0.0.1:80;
listen 127.0.0.1:80; server_name H2;
server_name internal_web_site; root /var/www/html;
index index.html;
location / { location / {
root /var/www/; try_files $uri $uri/ =404;
index index.html;
} }
} }
\ No newline at end of file
...@@ -2,12 +2,6 @@ ...@@ -2,12 +2,6 @@
Address = 10.0.0.1/24 Address = 10.0.0.1/24
PrivateKey = {{ keys["H2PRIV"] }} PrivateKey = {{ keys["H2PRIV"] }}
ListenPort = 51820 ListenPort = 51820
{# PostUp = nft -f nft.sh %i #}
{# PostUp = nft add rule ip nat POSTROUTING oifname "eth0" counter masquerade;nft add rule ip filter FORWARD iifname "eth0" counter accept
PostDown = nft del rule ip nat POSTROUTING oifname "eth0" counter masquerade;nft del rule ip filter FORWARD iifname "eth0" counter accept #}
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer] [Peer]
PublicKey = {{ keys["H1PUB"] }} PublicKey = {{ keys["H1PUB"] }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment