Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quote slash (/) as a key separator when communicating with augeas #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions lib/puppet/provider/sysctl/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
optional_commands :sysctl => 'sysctl'

resource_path do |resource|
"$target/#{resource[:name]}"
"$target/#{resource[:name]&.gsub('/', '\/')}"
end

def self.sysctl_set(key, value, silent=false)
Expand Down Expand Up @@ -46,7 +46,7 @@ def self.collect_augeas_resources(res, entries, target='/etc/sysctl.conf', resou
entries.each do |entry|
next if resources.find{|x| x[:name] == entry}

value = aug.get("$target/#{entry}")
value = aug.get("$target/#{entry.gsub('/', '\/')}")

if value
resource = {
Expand All @@ -59,11 +59,11 @@ def self.collect_augeas_resources(res, entries, target='/etc/sysctl.conf', resou

# Only match comments immediately before the entry and prefixed with
# the sysctl name
cmtnode = aug.match("$target/#comment[following-sibling::*[1][self::#{entry}]]")
cmtnode = aug.match("$target/#comment[following-sibling::*[1][self::#{entry.gsub('/', '\/')}]]")
unless cmtnode.empty?
comment = aug.get(cmtnode[0])
if comment.match(/#{resource[:name]}:/)
resource[:comment] = comment.sub(/^#{resource[:name]}:\s*/, "")
if comment.match(/#{resource[:name]&.gsub('/', '\/')}:/)
resource[:comment] = comment.sub(/^#{resource[:name]&.gsub('/', '\/')}:\s*/, "")
end
end

Expand Down Expand Up @@ -268,7 +268,7 @@ def live_value
if aug.match(cmtnode).empty?
aug.insert('$resource', "#comment", true)
end
aug.set("$target/#comment[following-sibling::*[1][self::#{resource[:name]}]]",
aug.set("$target/#comment[following-sibling::*[1][self::#{resource[:name]&.gsub('/', '\/')}]]",
"#{resource[:name]}: #{resource[:comment]}")
end
end
Expand Down
Loading