Commit 5db4c700 authored by 神楽坂玲奈's avatar 神楽坂玲奈

scripts

parent 1184935d
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
copy: copy:
src: scripts/postup.sh src: scripts/postup.sh
dest: '/etc/wireguard/postup.sh' dest: '/etc/wireguard/postup.sh'
mode: u+x mode: a+x
- name: predown - name: predown
copy: copy:
src: scripts/predown.sh src: scripts/predown.sh
dest: '/etc/wireguard/predown.sh' dest: '/etc/wireguard/predown.sh'
mode: u+x mode: a+x
- name: 'loop through list from a variable' - name: 'loop through list from a variable'
include_tasks: 'protocols/{{item.protocol}}/{{item.protocol}}.yaml' include_tasks: 'protocols/{{item.protocol}}/{{item.protocol}}.yaml'
vars: vars:
......
[Interface] [Interface]
Address = {{address}} Address = {{address}}/32
PrivateKey = {{key}} PrivateKey = {{key}}
ListenPort = {{conn.localPort}} ListenPort = {{conn.localPort}}
{% if gwmark is defined %} {% if gwmark is defined %}
FwMark = {{conn.localGatewayMark}} FwMark = {{conn.localGatewayMark}}
{% endif %} {% endif %}
Table = off Table = off
PostUp = "dev='%i' localPeerAddress='{{conn.localPeerAddress}}' remoteMark='{{conn.remoteMark}}' {% if conn.inbound is defined %}inbound='{{conn.inbound}}'{% endif %} {% if conn.mtu is defined %}mtu='{{conn.mtu}}'{% endif %} /etc/wireguard/postup.sh" PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} {% if conn.inbound is defined %}inbound={{conn.inbound}}{% endif %} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/postup.sh
PreDown = "dev='%i' localPeerAddress='{{conn.localPeerAddress}}' remoteMark='{{conn.remoteMark}}' {% if conn.inbound is defined %}inbound='{{conn.inbound}}'{% endif %} {% if conn.mtu is defined %}mtu='{{conn.mtu}}'{% endif %} /etc/wireguard/predown.sh" PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} {% if conn.inbound is defined %}inbound={{conn.inbound}}{% endif %} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/predown.sh
[Peer] [Peer]
PublicKey = {{conn.wgPublicKey}} PublicKey = {{conn.wgPublicKey}}
AllowedIPs = 0.0.0.0/0, ::/0 AllowedIPs = 0.0.0.0/0, ::/0
{% if endpoint is not defined %} {% if conn.remoteAddress is defined %}
Endpoint = {{conn.remoteAddress}}:{{conn.remotePort}} Endpoint = {{conn.remoteAddress}}:{{conn.remotePort}}
{% endif %} {% endif %}
...@@ -2,3 +2,8 @@ ...@@ -2,3 +2,8 @@
template: template:
src: wg.conf.j2 src: wg.conf.j2
dest: '/etc/wireguard/{{conn.name}}.conf' dest: '/etc/wireguard/{{conn.name}}.conf'
- name: enable
systemd:
name: 'wg-quick@{{conn.name}}'
state: started
enabled: yes
\ No newline at end of file
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
ip addr add "$loadlPeerAddress" peer "$remotePeerAddress" dev "$dev" ip addr add "$localPeerAddress" peer "$remotePeerAddress" dev "$dev"
if [ "$inbound" != true ] ; then if [ "$inbound" != True ] ; then
ip route add default dev "$dev" table "$remoteMark" ip route add default dev "$dev" table "$remoteMark"
ip rule add fwmark "$remoteMark" table "$remoteMark" pref 300 ip rule add fwmark "$remoteMark" table "$remoteMark" pref 300
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment