From 7ce3190986cf8e5fe037a7ccd4c1076505b117f4 Mon Sep 17 00:00:00 2001 From: Micah Date: Tue, 12 Jul 2016 16:41:59 -0400 Subject: remove submodules in preparation for move to subrepos Change-Id: Ia7655153b556337f676e3d909559c4a7306bedd6 --- puppet/modules/augeas | 1 - 1 file changed, 1 deletion(-) delete mode 160000 puppet/modules/augeas (limited to 'puppet/modules/augeas/lib') diff --git a/puppet/modules/augeas b/puppet/modules/augeas deleted file mode 160000 index 58ab2b90..00000000 --- a/puppet/modules/augeas +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 58ab2b90c52a5d951fa41596827bc3b6f52310e7 -- cgit v1.2.3 From 95374aacb857ed35c2fdfe6be7c0bfab86653963 Mon Sep 17 00:00:00 2001 From: Micah Date: Tue, 12 Jul 2016 16:46:07 -0400 Subject: git subrepo clone https://leap.se/git/puppet_augeas puppet/modules/augeas subrepo: subdir: "puppet/modules/augeas" merged: "27e3359" upstream: origin: "https://leap.se/git/puppet_augeas" branch: "master" commit: "27e3359" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "1e79595" Change-Id: Ifa5c7daf3f1be1793c42f873a267b7498f5c6c0f --- .../augeas/lib/puppet/parser/functions/augeas.rb | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 puppet/modules/augeas/lib/puppet/parser/functions/augeas.rb (limited to 'puppet/modules/augeas/lib') diff --git a/puppet/modules/augeas/lib/puppet/parser/functions/augeas.rb b/puppet/modules/augeas/lib/puppet/parser/functions/augeas.rb new file mode 100644 index 00000000..08026f77 --- /dev/null +++ b/puppet/modules/augeas/lib/puppet/parser/functions/augeas.rb @@ -0,0 +1,68 @@ +# +# augeas.rb +# + +module Puppet::Parser::Functions + newfunction(:augeas, :type => :rvalue, :doc => <<-EOS +Modifies a string using Augeas. + +*Example:* + + augeas("proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns', ['rm ./1/opt[3]']) + +Would result in: + + "proc /proc proc nodev,noexec 0 0\n" + EOS + ) do |arguments| + unless Puppet.features.augeas? + raise Puppet::ParseError, ('augeas(): this function requires the augeas feature. See http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas#Pre-requisites for how to activate it.') + end + + # Check that 2 arguments have been given ... + raise(Puppet::ParseError, 'augeas(): Wrong number of arguments ' + + "given (#{arguments.size} for 3)") if arguments.size != 3 + + content = arguments[0] + lens = arguments[1] + changes = arguments[2] + + # Check arguments + raise(Puppet::ParseError, 'augeas(): content must be a string') unless content.is_a?(String) + raise(Puppet::ParseError, 'augeas(): lens must be a string') unless lens.is_a?(String) + raise(Puppet::ParseError, 'augeas(): changes must be an array') unless changes.is_a?(Array) + + require 'augeas' + aug = Augeas::open(nil, nil, Augeas::NO_MODL_AUTOLOAD) + augeas_version = aug.get('/augeas/version') + raise(Puppet::ParseError, 'augeas(): requires Augeas 1.0.0 or greater') unless Puppet::Util::Package.versioncmp(augeas_version, '1.0.0') >= 0 + raise(Puppet::ParseError, 'augeas(): requires ruby-augeas 0.5.0 or greater') unless aug.methods.include?('text_store') + + result = nil + begin + aug.set('/input', content) + aug.text_store(lens, '/input', '/store') + unless aug.match("/augeas/text/store//error").empty? + error = aug.get("/augeas/text/store//error/message") + raise Puppet::ParseError, "augeas(): Failed to parse string with lens #{lens}: #{error}" + end + + # Apply changes + aug.context = '/store' + changes.each do |c| + r = aug.srun(c) + raise Puppet::ParseError, "augeas(): Failed to apply change to tree" unless r and r[0] >= 0 + end + unless aug.text_retrieve(lens, '/input', '/store', '/output') + error = aug.get("/augeas/text/store//error/message") + raise Puppet::ParseError, "augeas(): Failed to apply changes with lens #{lens}: #{error}" + end + result = aug.get("/output") + ensure + aug.close + end + return result + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3