Resource Type: xmlfile_modification

Defined in:
lib/puppet/type/xmlfile_modification.rb

Overview

Apply a change or an array of changes constrained by conditionals, to a specified xml file using syntax similar to the augeas XML lens. Changes are applied in memory during content generation when the catalog is applied.

Requires:

  • REXML

Sample usage with strings:

xmlfile_modification{"test" :
  file    => "/etc/activemq/activemq.conf.xml",
  changes => "set /beans/broker/transportConnectors/transportConnector[last()+1]/#attribute/name \"test\"",
  onlyif  => "match /beans/broker/transportConnectors/transportConnector[#attribute/name == \"test\"] size < 1",
}

Sample usage with arrays:

xmlfile_modification{"test" :
  file    => "/etc/activemq/activemq.conf.xml",
  changes => [ "set /beans/broker/transportConnectors/transportConnector[last()+1]/#attribute/name \"tests\"",
               "set /beans/broker/transportConnectors/transportConnector[last()+1]/#attribute/value \"tests\""],
  onlyif =>  [ "match /beans/broker/transportConnectors/transportConnector[#attribute/name == \"tests\"] size < 1" ],
}

Parameters

  • changes (defaults to: Array.new)

    Changes which should be applied to the file. Can be a command or an array of commands. Augeas-esque syntax.

    Paths are XPATHs. Attributes are matched via #attribute/<ATTR>, or assumed to be text. Evaluations must be bracketed.

    Commands:

    • set <PATH> “<VALUE>”

    : Sets the path to value, creates it if it does not exist

    • rm <PATH>

    : Removes the path.

    • clear <PATH>

    : Clears the specied path. Does not create it.

    • ins <PATH> (before|after) <LOCATION>

    : Constructs an element(or elements) using path and inserts it before or after the path specified by location

    • sort <PATH> (<VALUE>|text)

    : Sorts all elements that match path by the attribute specified in value.

    Path Functions:

    • last()

    : During initial parsing, substitutes for the index of the last item that matches the expression.

  • file

    The path of the xmlfile to work with.

  • onlyif (defaults to: Array.new)

    Constrains application of changes via conditionals. Augeas-esque syntax.

    Paths are XPATHs. Attributes are matched via #attribute/<ATTR>, or assumed to be text. Evaluations must be bracketed.

    Commands:

    • match <PATH> size (==|!=|<|>|<=|>=) <VALUE>

    : Evaluates if a match for the given path meets the conditions specified.

    • get <PATH> (==|!=|<|>|<=|>=) <VALUE>

    : Checks if a path matches a given value under the conditions specified

    Path Functions:

    • last()

    : During initial parsing, substitutes for the index of the last item that matches the expression.