Ask Your Question
1

Puppet Array in hiera

asked 2017-05-18 06:43:05 -0500

bigfoot74 gravatar image

updated 2017-05-18 06:46:15 -0500

Hello,

I am trying to rewrite some puppet apache profiles we have, also trying to remove array etc and move them to hiera. Does anyone know how to add this to hiera:

   $aliases = [{
    scriptalias => '/awstats',
    path        => '/usr/lib/cgi-bin/',   }   ,   {
    alias => '/awstats-icon',
    path  => '/usr/share/awstats/icon/',   }   ,   {
    alias => '/awstatsclasses',
    path  => '/usr/share/awstats/lib/',   }   ,   {
    alias => '/awstatscss',
    path  => '/usr/share/doc/awstats/examples/css', }   ]

I tried something like:

profile::apache::httpd::someapache:aliases:
    - alias:
        - '/awstatsclasses'
        - '/awstats-icon'
    - path:
        - '/usr/share/awstats/lib/'
        - '/usr/share/awstats/icon/'

But it keeps overwriting the Alias line with the last values....

Could someone help me please ?

Kind regards,

  • Pascal den Bekker
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2017-05-18 10:38:47 -0500

smarlow gravatar image

When writing tricky structures in YAML I would recommend using an interactive parser like this one.

In order to convert that over you would need to express it like so:

profile::apache::httpd::someapache::aliases:
    - scriptalias: '/awstats'
      path:  '/usr/lib/cgi-bin/'
    - alias: '/awstats-icon'
      path:  '/usr/share/awstats/icon/'
    - alias: '/awstatsclasses'
      path:  '/usr/share/awstats/lib/'
    - alias: '/awstatscss'
      path:  '/usr/share/doc/awstats/examples/css'

Basically you need an array of hashes, each hash with the same keys/values as in the original. There's no need to condense all of the aliases/paths into a single key.

edit flag offensive delete link more

Comments

I tend to write out my structures in irb, and dump it to a yaml file to verify, but the interactive parser is probably better. Also, JSON is a subset of yaml, so if you are more comfortable, you can just write it as json and parse it as yaml

DarylW gravatar imageDarylW ( 2017-05-19 21:26:10 -0500 )edit
0

answered 2017-05-19 01:04:29 -0500

bigfoot74 gravatar image

Thnx smarlow :-) That helped me a lot :-)

edit flag offensive delete link more
0

answered 2017-05-18 09:37:53 -0500

dcs02d gravatar image

Get rid of the - for the keys (alias and path)

profile::apache::httpd::someapache:aliases: alias: - '/awstatsclasses' - '/awstats-icon' path: - '/usr/share/awstats/lib/' - '/usr/share/awstats/icon/'

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-05-18 06:43:05 -0500

Seen: 45 times

Last updated: May 19