Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ansible-TP3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fabian.troller
Ansible-TP3
Commits
3312477c
"slides_2023/cours_12.md" did not exist on "0550c9c32aeb36546d6d12528b883c4abd627c9d"
Commit
3312477c
authored
2 years ago
by
poulpe
Browse files
Options
Downloads
Patches
Plain Diff
[Update+fix] Fix wireguard startup + fix nginx config
parent
856ea2d1
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Config_Wireguard.yml
+51
-11
51 additions, 11 deletions
Config_Wireguard.yml
templates/nginx_config_template.j2
+7
-7
7 additions, 7 deletions
templates/nginx_config_template.j2
templates/wireguard_config_template_H2.j2
+0
-6
0 additions, 6 deletions
templates/wireguard_config_template_H2.j2
with
58 additions
and
24 deletions
Config_Wireguard.yml
+
51
−
11
View file @
3312477c
...
@@ -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
:
0
640
mode
:
0
777
-
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
This diff is collapsed.
Click to expand it.
templates/nginx_config_template.j2
+
7
−
7
View file @
3312477c
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
This diff is collapsed.
Click to expand it.
templates/wireguard_config_template_H2.j2
+
0
−
6
View file @
3312477c
...
@@ -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"] }}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment