From c503180c5100b3c2981b08ddec766fd4b55fec7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 25 Jan 2022 00:28:50 +0100 Subject: Augas test. --- manifests/syncthing.pp | 57 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'manifests/syncthing.pp') diff --git a/manifests/syncthing.pp b/manifests/syncthing.pp index 9580905..0a30851 100644 --- a/manifests/syncthing.pp +++ b/manifests/syncthing.pp @@ -1,6 +1,7 @@ class profiles::syncthing ( $data, Array[String] $enable_for = [], + Array[String] $augrules = [], ) { case $facts['osfamily'] { @@ -59,11 +60,57 @@ class profiles::syncthing ( # enable => true, # } - augeas { 'syncthing_config': - context => "/files/home/${user}.config/syncthing/config.xml/configuration", - changes => [ - 'set gui/#attribute/enabled false', - ], + # 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', + # ], } } -- cgit v1.2.3