diff --git a/modules/wireguard.py b/modules/wireguard.py index 8511483d..81a06a82 100644 --- a/modules/wireguard.py +++ b/modules/wireguard.py @@ -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 diff --git a/modules/wireguard/manifests/init.pp b/modules/wireguard/manifests/init.pp index 755f3a08..7a7b6304 100644 --- a/modules/wireguard/manifests/init.pp +++ b/modules/wireguard/manifests/init.pp @@ -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 @@ -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', } @@ -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', } }