Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions modules/wireguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file

import lib

def generate(host, *args):
return {'wireguard': None}

# Get current event, used to get up-to-date switch conf
current_event = lib.get_current_event()

info = {}
info['current_event'] = current_event
return {'wireguard': info}

# vim: ts=4: sts=4: sw=4: expandtab
13 changes: 8 additions & 5 deletions modules/wireguard/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class wireguard {
class wireguard($current_event) {
# Execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
Expand All @@ -20,29 +20,32 @@
exec { 'create-privkey':
command => '/usr/bin/wg pubkey < /etc/wireguard/privkey > /etc/wireguard/pubkey',
unless => '/usr/bin/ls /etc/wireguard/privkey'
require => Exec['create'],
}

exec { 'create-pubkey':
command => '/usr/bin/wg genkey > /etc/wireguard/privkey',
unless => '/usr/bin/ls /etc/wireguard/privkey'
require => Exec['create-privkey'],
}


exec { 'add-key':
command => '/usr/bin/wg set wg0 listen-port 51820 private-key /etc/wireguard/privkey',
require => Exec['create-key'], # require 'apt-update' before installing
require => Exec['create-pubkey'],
}


# Set wireguard interface IP
exec { 'set wg interface IP':
require => Package['wireguard'],
exec { 'set-IP':
require => Exec['add-key'],
command => '/usr/bin/ip address add dev wg0 77.80.229.133/25',
unless => '/usr/bin/ip addr show wg0 | grep 77.80.229.133/25'
}

file { '/etc/wireguard/yaml':
ensure => directory,
require => Exec['set-IP'],
recurse => remote,
source => 'puppet:///svn/$::{current_event}/services/wireguard',
}
Expand All @@ -59,7 +62,7 @@

# Sync changes towards the wg0 interface
exec { 'syncConf':
require => Package['wireguard'],
require => file['setConf'],
command => '/usr/bin/wg syncconf wg0 /etc/wireguard/wg0.conf',
}
}