Git Product home page Git Product logo

puppet-module-yamlfile's Introduction

yamlfile

yamlfile module with yaml_setting type+provider, a la Chris Price’ inifile module / ini_setting type+provider

This is an experimental utility module allowing for more dynamic configuration of the myriad of yaml files used to configure various yaml-configured ruby applications with finer grained control than templates would easily allow.

A rapid prototype provider is included built using Adrien Thebo’s filemapper utility module. It won’t account for comments but it mostly works.

Usage

The type interface is probably the hardest part and is largely a design question. The prototype says screw it, K.I.S.S., and assumes hashes are the most common thing to be dealing with for yaml configuration files. As such a pair of resources given as:

yaml_setting { 'example1_1':
  target => '/tmp/example1.yaml',
  key    => 'value/subkey/final',
  value  => ['one', 'two', 'three'],
}
yaml_setting { 'example1_2':
  target => '/tmp/example1.yaml',
  key    => 'value/subkey/other':
  value  => 'string',
}

should result in a file e.g. /tmp/example1.yaml:

value:
  subkey:
    final:
      - one
      - two
      - three
    other: string

Known Issues

Right now the type design doesn't allow for ruby symbols to be used as keys.

There are no tests.

puppet-module-yamlfile's People

Contributors

iivvaall avatar nanliu avatar reidmv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puppet-module-yamlfile's Issues

Add ensure => 'absent'

Is there a way to ensure a specific key to be absent in the target? Such a feature would be very handy in many use cases.

Getting Escape Sequences in my values

Gettting "[\x22{value}\x22]" instead of "{value}".

I'm trying to configure ldap for the puppet master and have the following in the manifest:

yaml_setting { 'ad_cas_client_config':
    target => '/etc/puppetlabs/console-auth/cas_client_config.yml',
    key    => 'authorization/ldap/default_role',
    value  => 'read-only',
}

This ouptputs:


---
authorization:
  ldap:
    default_role: "[\x22read-only\x22]"
  local:
    default_role: "[\x22read-only\x22]"
    description: "[\x22Local\x22]"
...

Not compatible with latest filemapper module

This module appears not to work correctly with the latest filemapper releases (now maintained by the Vox Pupuli project). It is not idempotent and doesn't preserve non-managed parts of the yaml file.

eg

[root@localhost ~]# cat test.yml
transports:
  rest.agent.transport:
    enabled: false
  websocket.transport:
    consoleUri: wss://mule-manager.anypoint.mulesoft.com:443/mule
    handshake:
      enabled: true
      body: null
globalConfiguration:
  security:
    keyStoreAlias: agent
  authenticationProxy:
    endpoint: https://arm-auth-proxy.prod.cloudhub.io
  proxyConfiguration:
    host: 1.1.1.1
    port: '3128'
internalHandlers:
  mule.agent.tracking.handler.analytics:
    enabled: false
[root@localhost ~]# cat test.pp
yaml_setting { 'mule agent proxy host':
      target  => '/root/test.yml',
      key     => 'globalConfiguration/proxyConfiguration/host',
      value   => 'host.example.com',
}
[root@localhost ~]# puppet apply --modulepath=/root/modules test.pp
Notice: Compiled catalog for localhost in environment production in 0.09 seconds
Notice: /Stage[main]/Main/Yaml_setting[mule agent proxy host]/ensure: created
Notice: Applied catalog in 0.11 seconds
[root@localhost ~]# cat test.yml
---
globalConfiguration:
  proxyConfiguration:
    host: host.example.com

[root@localhost ~]#

If I use adrien/filemapper, everything works fine.

I've been able to work out it was voxpupuli/puppet-filemapper#10 that broke this module, but have no idea how to fix it! Any ideas? Thanks.

Minimal manipulation of original file

I realize this is currently just an experimental initial implementation, but it would be great if at some point this module also implemented the following feature of the inifile module...

The module tries hard not to manipulate your file any more than it needs to. In most cases, it should leave the original whitespace, comments, ordering, etc. perfectly intact.

https://forge.puppetlabs.com/puppetlabs/inifile

For example, when using the yaml_setting type to manage the time_zone setting in the puppet-dashboard/settings.yml file, it clobers all the helpful comments that originally exist in the file.

Boolean type is not idempotent

Hi - When attempting to use this modual, when assigning boolean to the type, every puppet run, it wrote the value to the file, even though it did not change.

yaml_setting { 'ssl_true':
target => '/usr/global/newrelic/3.12.0/newrelic.yml',
key => 'common/ssl',
type => 'boolean',
value => 'true',
}

Here is the output from the run. This output would happen for each run.

Notice: /Stage[main]/Newrelic::Config/Yaml_setting[private_ssl]/value: value changed 'true' to 'true'
Info: Computing checksum on file /usr/global/newrelic/3.12.0/newrelic.yml
Info: FileBucket got a duplicate file {md5}d8f6f55c33de0fd35705d5212e1fe707

Initial indentation problem

I'm using your module which is God sent for getting close to the same functionality as Augeas in Puppet for YAML files.
However I have a problem with tools that are used in Symfony to parse the generated yml file.

Specifically, your module adds an initial indentation from the root of the tree.

I think this might be an error. Is there a way I can prevent that?

Singleton array

I was developing some Puppet code to create YAML for bind resource records (using Inkblots bind module) out of existing Hiera data (for server network interfaces) when I came across this in my test code:

yaml_setting {
"host1_rrdata":
   target => "/tmp/yaml_setting.yaml",
   key => "dns_rrs/host1/rrdata",
   value => [ "10.0.0.1" ];
 }

results in
dns_rrs:
host1:
rrdata: "10.0.0.1"

rather than the expected
dns_rrs:
host1:
rrdata:
- "10.0.0.1"

specifying type => 'array' made it generate a YAML array but I think giving it an array, even with one element, should have worked.

If I gave it an array with multiple entries in the Puppet code it worked fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.