From 423ff522158d9256841c0441cd1e2a9b50de3c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 25 Jan 2022 01:31:42 +0100 Subject: Rewrite syncthing profile to use module. --- manifests/syncthing.pp | 177 +++++++++++++++++++++++++------------------------ 1 file changed, 92 insertions(+), 85 deletions(-) (limited to 'manifests/syncthing.pp') diff --git a/manifests/syncthing.pp b/manifests/syncthing.pp index 0a30851..e31449a 100644 --- a/manifests/syncthing.pp +++ b/manifests/syncthing.pp @@ -4,33 +4,14 @@ class profiles::syncthing ( Array[String] $augrules = [], ) { - case $facts['osfamily'] { - 'Debian': { - file { '/etc/apt/trusted.gpg.d/syncthing.gpg': - ensure => file, - source => 'https://syncthing.net/release-key.gpg', - checksum => 'sha256', - checksum_value => 'a3806c3511f2cce3d2f12962f64b58b9192a15c9d862886cc46f9de8a25d7dbf', - } - - ensure_resource(exec, { 'apt update' => { refreshonly => true }}) - - file { '/etc/apt/sources.list.d/syncthing.list': - content => "deb https://apt.syncthing.net/ syncthing stable\n", - # TODO more general way to add apt repos - notify => Exec['apt update'], - before => Package['syncthing'] - } - } - } - - package { 'syncthing': - ensure => installed + class { 'syncthing': + manage_repo => $::osfamily == 'Debian', } systemd::dropin_file { 'nospam.conf': - unit => 'syncthing@.service', + ensure => absent, + unit => 'syncthing@.service', content => @(EOF) [Service] ExecStart= @@ -45,76 +26,102 @@ class profiles::syncthing ( managehome => true, } - $dir = "/home/${user}/.config/syncthing" - file { "/home/${user}/.config": - ensure => directory, - owner => $user, - group => $user, + + $hp = "/home/${user}/.config/syncthing" + + syncthing::instance { $user: + home_path => $hp, + daemon_uid => $user, } - exec { "/usr/bin/syncthing -generate='${dir}'": - user => $user, - creates => $dir, + + $data['devices'].each |$name, $d| { + syncthing::device { $name: + home_path => $hp, + instance_name => $user, + id => $d['id'], + } } - # service { "syncthing@${user}": - # enable => true, - # } + $data['folders'].each |$name, $d| { + syncthing::folder { $name: + home_path => $hp, + instance_name => $user, + id => $d['id'], + path => $d['path'], + devices => $d['devices'].map |$name| { [ $data['devices'][$name]['id'], 'present' ] }.hash + } + } - # augeas { 'syncthing_config': - # # context => "/files/home/${user}.config/syncthing/config.xml/configuration", - # changes => [ - # "defvar base /home/${user}/.config/syncthing/", - # 'set /augeas/load/Xml/incl[1] $base/*.xml', - # 'load', - # 'defvar $ctx $base/config.xml/configuration', - # 'set $ctx/gui/#attribute/enabled false', - # 'save', - # 'rm $ctx/folder/', - # 'set $ctx/folder[0]/#attribute/label Documentns', - # 'set $ctx/folder[0]/#attribute/path ~/sync/doc', - # 'set $ctx/folder[0]/#attribute/id rrrr-xxxx', - # 'set $ctx/folder[0]/#attribute/device[0]/#attribute/id something-really-long', - # 'save', - # ], + # $dir = "/home/${user}/.config/syncthing" + # file { "/home/${user}/.config": + # ensure => directory, + # owner => $user, + # group => $user, + # } + # exec { "/usr/bin/syncthing -generate='${dir}'": + # user => $user, + # creates => $dir, # } - $device_rules = flatten($data['devices'].map |$name, $d| { - [ - "defnode node device[#attribute/name=$name] ''", - "set \$node/#attribute/name ${name}", - "set \$node/#attribute/id ${d['id']}", - ] - }) - - $folder_rules = flatten($data['folders'].map |$name, $d| { - [ - "defnode node folder[#attribute/label=$name] ''", - "set \$node/#attribute/label ${name}", - "set \$node/#attribute/path ${d['path']}", - "set \$node/#attribute/id ${d['id']}", - ] + flatten($d['devices'].map |$name| { - alert($name) - alert($data['devices'][$name]) - [ "set \$node/device[0]/#attribute/id ${data['devices'][$name]['id']}", ] - }) - }) - - augeas { 'syncthing-config': - lens => 'Xml.lns', - incl => "/home/${user}/.config/syncthing/config.xml", - context => "/files/home/${user}/.config/syncthing/config.xml/configuration", - changes => $device_rules + $folder_rules, - # [ - # 'rm folder/', - # 'set folder[0]/#attribute/label Documentsn', - # 'set folder[0]/#attribute/path ~/sync/doc', - # # 'set folder[0]/#attribute/id rrrr-xxxx', - # # 'set folder[0]/#attribute/device[0]/#attribute/id something-really-long', - # ], - } + # # service { "syncthing@${user}": + # # enable => true, + # # } + + # # augeas { 'syncthing_config': + # # # context => "/files/home/${user}.config/syncthing/config.xml/configuration", + # # changes => [ + # # "defvar base /home/${user}/.config/syncthing/", + # # 'set /augeas/load/Xml/incl[1] $base/*.xml', + # # 'load', + # # 'defvar $ctx $base/config.xml/configuration', + # # 'set $ctx/gui/#attribute/enabled false', + # # 'save', + # # 'rm $ctx/folder/', + # # 'set $ctx/folder[0]/#attribute/label Documentns', + # # 'set $ctx/folder[0]/#attribute/path ~/sync/doc', + # # 'set $ctx/folder[0]/#attribute/id rrrr-xxxx', + # # 'set $ctx/folder[0]/#attribute/device[0]/#attribute/id something-really-long', + # # 'save', + # # ], + # # } + + # $device_rules = flatten($data['devices'].map |$name, $d| { + # [ + # "defnode node device[#attribute/name=$name] ''", + # "set \$node/#attribute/name ${name}", + # "set \$node/#attribute/id ${d['id']}", + # ] + # }) + + # $folder_rules = flatten($data['folders'].map |$name, $d| { + # [ + # "defnode node folder[#attribute/label=$name] ''", + # "set \$node/#attribute/label ${name}", + # "set \$node/#attribute/path ${d['path']}", + # "set \$node/#attribute/id ${d['id']}", + # ] + flatten($d['devices'].map |$name| { + # alert($name) + # alert($data['devices'][$name]) + # [ "set \$node/device[0]/#attribute/id ${data['devices'][$name]['id']}", ] + # }) + # }) + + # augeas { 'syncthing-config': + # lens => 'Xml.lns', + # incl => "/home/${user}/.config/syncthing/config.xml", + # context => "/files/home/${user}/.config/syncthing/config.xml/configuration", + # changes => $device_rules + $folder_rules, + # # [ + # # 'rm folder/', + # # 'set folder[0]/#attribute/label Documentsn', + # # 'set folder[0]/#attribute/path ~/sync/doc', + # # # 'set folder[0]/#attribute/id rrrr-xxxx', + # # # 'set folder[0]/#attribute/device[0]/#attribute/id something-really-long', + # # ], + # } } - # TODO manage synced data + # # TODO manage synced data } -- cgit v1.2.3