Forge Home

hash_to_xml

Convert a Puppet hash into XML data

3,210 downloads

3,210 latest version

5.0 quality score

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
  • RedHat
    ,
    CentOS
    ,
    SLES
    ,
    Ubuntu

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.

Download
Tags: xml

Documentation

WhatsARanjit/hash_to_xml — version 0.0.1 Jul 24th 2019

hash_to_xml

Table of Contents

  1. Overview
  2. Functions

Overview

Convert a Puppet hash into XML data.

Functions

hash_to_xml()

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"?>
<xml>
  <fruit>apple</fruit>
  <vegetables>
    <green>cucumber</green>
    <brown>potato</brown>
  </vegetables>
  <nested>
    <one>
      <foo>bar</foo>
    </one>
    <two>
      <foo>bar</foo>
    </two>
  </nested>
</xml>

Arguments:

  • 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"?>

    Required

  • 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

Maintainers

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.