Forge Home

xmlfile

Augeas like syntax for managing xml files across windows and unix

762 downloads

762 latest version

4.1 quality score

Version information

  • 1.0.0 (latest)
released Jun 13th 2021
This version is compatible with:
  • Puppet Enterprise 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x
  • Puppet >= 6.1.0 < 8.0.0

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'puppet-xmlfile', '1.0.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add puppet-xmlfile
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install puppet-xmlfile --version 1.0.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

puppet/xmlfile — version 1.0.0 Jun 13th 2021

Puppet XMLFile Library

License

Table of Contents

  1. Overview - What is the xmlfile module?
  2. Why - Reasoning for developing this module
  3. Implementation - Summary of the under the hood implementation of the module
  4. Limitations - Known issues and limitations of the implementation

Overview

If you have ever wanted to use augeas like syntax for xml files without the use of augeas the xmlfile module is for you.

NOTE Augeas does not work on Windows.

The xmlfile type overrides the file type and inherits most of the file type attributes. Additionally, xmlfile type will process all xmlfile_modification resources and write them out to the xmlfile without causing resource conflicts or overwriting previously modified xml files.

Works on POSIX and Windows systems.

Usage

To use you first must declare an xmlfile resource. You can initially set the source or content or any other type of file based attribute.

Once the xmlfile resource is declared, you can further modify the xmlfile with the xmlfile_modification type with augeas like syntax.

$mq_xml_file = "/etc/activemq/activemq.conf.xml"
xmlfile { $mq_xml_file:
  ensure => present
}

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

xmlfile_modification { "test2":
  file    => $mq_xml_file,
  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" ],
}

Why?

While working on a variety of modules I kept running into cases where what I really, really wanted to do was apply augeas lenses to a template, but this was problematic. There were several options for this, none of them good. I could use a file concat library, and sandwich augeas and file types that way, have a triggered exec resource, etc. No matter what we're basically managing multiple resources when what we really want is just one and some changes. Just no good way to really deal with it.

My first thought was "my kingdom for an array!" which led to the databucket library, the idea behind which was to do collection of resource parameters at catalog compilation into an array, and then use that within the template. This idea, while cool, is, unfortunately, probably not reliable enough for production or capable of being made reliable enough for production. So collecting and using virtual or exported data and directly referencing it(IE: in a template) is out.

Hence this, which sidetracks the whole issue.

Implementation

By extending the Puppet file type and using some providers we can merge templated or sourced content and modifications and have puppet treat this content as if it had been passed directly.

The changes themselves are applied via the XmlLens class, which fakes being augeas. This is accomplished via the standard ruby REXML library. Upshot of this is we can add in things like sorting.

Limitations

I don't have a complete Windows puppet kit and so while we extend the Windows provider and it should work, I can't actually test it.

Property fix is called via send on object creation. This may create a security issue when a file is first created if the properties are not correctly set, although this should get fixed on the next puppet run.

The augeas implementation is incomplete and not exact. If you notice an issue or unexpected behavior, please open an issue.

REXML has some limitations and quirks of its own. <, &, and > if by themselves will be automagically converted to &lt; &amp; and &gt; and there's no way to turn this off. Content is otherwise put into raw mode and so it shouldn't be messed with.

Authors

This module was originally forked from TERC/puppet-xmlfile. Many thanks to @cammoraton for the original work done.

  • @logicminds (NWOPS, LLC) Has further refined this module.