Forge Home


Convert a Puppet hash into XML data


3,949 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.0.1 (latest)
released Jul 24th 2019
This version is compatible with:
  • Puppet Enterprise 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
  • Puppet >= 3.7.1 < 6.0.0
  • , , ,

Start using this module

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

Add this module to your Puppetfile:

mod 'WhatsARanjit-hash_to_xml', '0.0.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add WhatsARanjit-hash_to_xml
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install WhatsARanjit-hash_to_xml --version 0.0.1

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.

Tags: xml


WhatsARanjit/hash_to_xml — version 0.0.1 Jul 24th 2019


Table of Contents

  1. Overview
  2. Functions


Convert a Puppet hash into XML data.



Convert a Puppet hash into XML data.

hash_to_xml() given the following data:

$data = {
  '?xml version="1.0" encoding="UTF-8"?' => false,
  'xml' => {
    'fruit' => 'apple',
    'vegetables' => {
      'green' => 'cucumber',
      'brown' => 'potato'
    'nested' => {
      'one' => {
        'foo' => 'bar',
      'two' => {
        'foo' => 'bar',

file { '/tmp/example.xml':
  ensure  => file,
  content => hash_to_xml($data),

The file at /tmp/example.xml will contain:

<?xml version="1.0" encoding="UTF-8"?>


  • data

    Puppet hash of intended XML data. Keys set to strings will be XML values like this:

    'key' => 'value' converts to `value``

    Keys set to hashes create opening and closing tags like this:

    parent => { ... } converts to <parent>...</parent>

    Keys set to false will open but not close like this:

    ?xml version="1.0" encoding="UTF-8"?' => false converts to <?xml version="1.0" encoding="UTF-8"?>


  • indent

    Starting indent in case you want to nest generated XML into other XML.

    Default: 0

  • indent character

    Chracter used for indent. Can be used to choose between tabs, spaces, etc.

    Default: \s

  • indent character count

    The number of indent characters to use. Can be used to decide 4 spaces, 2 tabs, etc.

    Default: 2

Type: rvalue


This repositority is largely the work of some Puppet community members. It is not officially maintained by Puppet, or any individual in particular. Issues should be opened in Github. Questions should be directed at the individuals responsible for committing that particular code.