2021-04-01 14:27:31 +00:00
|
|
|
from ipaddress import ip_network
|
|
|
|
|
2021-04-02 16:57:13 +00:00
|
|
|
repo.libs.tools.require_bundle(node, 'systemd-networkd')
|
2020-11-21 14:38:38 +00:00
|
|
|
|
2021-04-01 14:27:31 +00:00
|
|
|
network = ip_network(node.metadata['wireguard']['my_ip'], strict=False)
|
|
|
|
|
2020-11-21 14:38:38 +00:00
|
|
|
files = {
|
2021-04-01 14:27:31 +00:00
|
|
|
'/etc/systemd/network/wg0.netdev': {
|
2020-11-21 14:38:38 +00:00
|
|
|
'content_type': 'mako',
|
2021-04-01 14:27:31 +00:00
|
|
|
'context': {
|
|
|
|
'network': f'{network.network_address}/{network.prefixlen}',
|
|
|
|
**node.metadata['wireguard'],
|
2020-11-21 14:38:38 +00:00
|
|
|
},
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:wireguard',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 15:15:34 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_wireguard_connected': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-21 14:38:38 +00:00
|
|
|
}
|
2020-11-27 02:09:37 +00:00
|
|
|
|
|
|
|
if node.has_bundle('pppd'):
|
|
|
|
files['/etc/ppp/ip-up.d/reconnect-wireguard'] = {
|
|
|
|
'source': 'pppd-ip-up',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'mode': '0755',
|
|
|
|
}
|