Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a hash for the template #21

Closed
pjfoley opened this issue Sep 6, 2014 · 1 comment
Closed

Using a hash for the template #21

pjfoley opened this issue Sep 6, 2014 · 1 comment

Comments

@pjfoley
Copy link
Contributor

pjfoley commented Sep 6, 2014

Hi,

I am looking to extend this module to setup hiera to use hiera-file.

Firstly I am new to ruby programming, which is causing me to stumble on trying to make this module a little bit more generic. Essentially I am trying to work out a way to take a hash of values which can than be used within the template file to setup a range of hiera backends.

Here is how I have things setup so far:

I have a yaml file with this hash in it:

---
hiera::backends:
   yaml:
     datadir: '/root/dev/test'
   file:
     datadir: '/root/dev/foo'
   eyaml:
     datadir: '/root/dev/bar'
     pkcs7_private_key: '<%= @confdir %>/keys/private_key.pkcs7.pem'
     pkcs7_public_key: '<%= @confdir %>/keys/public_key.pkcs7.pem'

I than use hiera within puppet to pull the hash into a variable which the hiera.yaml.erg template will use:

 ---
:backends:
 <%= @testing.keys.to_yaml.split("\n")[1..-1].join("\n") %>

 <%= @testing.to_yaml.split("\n")[1..-1].join("\n") %>

It almost seems to work

---
:backends:
   - yaml
   - file
   - eyaml

   yaml:.
     datadir: /root/dev/test
   file:.
     datadir: /root/dev/foo
   eyaml:.
     datadir: /root/dev/bar
     pkcs7_private_key: "<%= @confdir %>/keys/private_key.pkcs7.pem"
     pkcs7_public_key: "<%= @confdir %>/keys/public_key.pkcs7.pem"

As you can see from the generated yaml file, ruby does not prepend a ":" (colon) in front of the keys and it also has indented the first key's.

Does anyone have any ideas on how I can modify the behaviour of the .to_yaml function to prepend a colon and not have it indent?

Thanks,

Peter

@igalic
Copy link
Contributor

igalic commented Sep 8, 2014

it doesn't do that, because you didn't do it in your has either.

@pjfoley pjfoley closed this as completed Sep 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants