-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
augeas.rb
76 lines (63 loc) · 2.22 KB
/
augeas.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf-8
# Alternative Augeas-based providers for Puppet
#
# Copyright (c) 2012 Raphaël Pinson
# Licensed under the Apache License, Version 2.0
raise("Missing augeasproviders_core dependency") if Puppet::Type.type(:augeasprovider).nil?
Puppet::Type.type(:sshd_config_subsystem).provide(:augeas, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do
desc "Uses Augeas API to update a Subsystem parameter in sshd_config."
default_file { '/etc/ssh/sshd_config' }
lens { 'Sshd.lns' }
confine :feature => :augeas
resource_path do |resource|
"$target/*[label()=~regexp('Subsystem', 'i')]/#{resource[:name]}"
end
def self.instances
augopen do |aug|
aug.match("$target/Subsystem/*").map do |hpath|
command = aug.get(hpath)
new({
:ensure => :present,
:name => path_label(aug, hpath),
:command => command
}) if command
end
end
end
def create
key = resource[:name]
augopen! do |aug|
unless aug.match("$target/Match").empty?
aug.insert("$target/Match[1]", "Subsystem", true)
aug.clear("$target/Subsystem[last()]/#{key}")
end
aug.set("$target/Subsystem/#{resource[:name]}", resource[:command])
self.comment = resource[:comment] if resource[:comment]
end
end
define_aug_method!(:destroy) do |aug, resource|
key = resource[:name]
aug.rm("$target/*[label()=~regexp('Subsystem', 'i') and #{key}]")
end
attr_aug_accessor(:command, :label => :resource)
def comment
augopen do |aug|
comment = aug.get("$target/#comment[following-sibling::*[1][label() =~ regexp('Subsystem', 'i') and #{resource[:name]}]]")
comment.sub!(/^#{resource[:name]}:\s*/i, "") if comment
comment || ""
end
end
def comment=(value)
augopen! do |aug|
cmtnode = "$target/#comment[following-sibling::*[1][label() =~ regexp('Subsystem', 'i') and #{resource[:name]}]]"
if value.empty?
aug.rm(cmtnode)
else
if aug.match(cmtnode).empty?
aug.insert("$target/*[label()=~regexp('Subsystem', 'i') and #{resource[:name]}]", "#comment", true)
end
aug.set(cmtnode, "#{resource[:name]}: #{resource[:comment]}")
end
end
end
end