Hi all,

I'm using puppet 5.3.

I'd like to build proxy_pass array of hashes using the *reduce *puppet
built-in function  <https://puppet.com/docs/puppet/5.5/function.html#reduce>and
picking the values from a nested hash in hiera.

I first played a little bit with the reduce function:

$dirs = ['static','media','photos']
$proxy = $dirs.reduce([ { 'path' => '/', 'url' => "http://localhost:
${port}/" } ]) |$memo, $value| { $memo + [ { 'path' => "/$value/", 'url' =>
'!' } ] }
notify { "MemoOut: $proxy" : ;}

If I puppet apply the above code the output looks like:

Notice: MemoOut: [{path => /, url => http://localhost:189/}, {path =>
/static/, url => !}, {path => /media/, url => !}, {path => /photos/, url =>
!}]
Notice: /Stage[main]/Main/Node[default]/Notify[MemoOut: [{path => /, url =>
http://localhost:189/}, {path => /static/, url => !}, {path => /media/, url
=> !}, {path => /photos/, url => !}]]/message: defined 'message' as 'MemoOut:
[{path => /, url => http://localhost:189/}, {path => /static/, url => !},
{path => /media/, url => !}, {path => /photos/, url => !}]'

*To my eyes this is an array of hashes, and that's what I need to pass to
the apache vhost define.*

So, now I want to pick the array (list of directories) from a nested hash
in hiera that look like:

  application:
    apache:
      enable: true
      servername: application
      static_served:
        - static

I have a define that picks the above hash.... The array with the list of
directories becomes "${apache['static_served']}" inside teh define.
I can print it using notice ${apache['static_served']}":

Notice: static_served: application [static]

This looks like an array but *is_array *says that this is *not *an array
anymore.
And this is my first question, why it is not an array anymore?


I make this an array using any2array (array un puppet 5) so I can still
call the reduce function::

$var=(Array("${apache['static_served']}"))

so the *reduce *line now looks like:

$_proxy_pass =  $var.reduce([ { 'path' => '/', 'url' => "http://localhost:
${port}/" } ]) |$memo, $value| { $memo + [ { 'path' => "/$value/", 'url' =>
'!' } ] }

And here is where everythiong starts to make even less sense:

If I print the output (using notice $_proxy_pass and )  and I get a weird
output:

Notice: /Stage[main]/.../Python::Virtualenv[application]/Notify[PROXY_PASS:
[{path => /, url => http://local
host:11080/}, {path => /[/, url => !}, {path => /s/, url => !}, {path => /t/,
url => !}, {path => /a/, url => !}, {path => /t/, url => !}, {path => /i/,
url => !},
 {path => /c/, url => !}, {path => /]/, url => !}]]/message: defined
'message' as 'PROXY_PASS: [{path => /, url => http://localhost:11080/},
{path => /[/, url => !
}, {path => /s/, url => !}, {path => /t/, url => !}, {path => /a/, url =>
!}, {path => /t/, url => !}, {path => /i/, url => !}, {path => /c/, url =>
!}, {path => /
]/, url => !}]'

reduce is taking all letters from "static" instead of 'static" as the first
(an uniqe) element from the array....

Later, in my code, I configure the proxy_pass in the apache:vhost like:

apache::vhost { "${apache['servername']}":
[...]
        proxy_pass     => "$_proxy_pass",
[...]

But, in the apache file, the proxy pass parameters  looks like

 ProxyPass path url
 ProxyPassReverse path url
 ProxyPass path url
 ProxyPassReverse path url
[...]

So it's picking the keys from the hashes in the above array of hashes and
not the values.

I don't understand what is going on. Any help will be appreciated.

Best,
Arnau

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAM69jx-wKXmP%3DhfPLsMsrYDeOS7TCTQaQ9XyhUaoWJ9uq%3DeZEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to