On 09/05/18 13:36, Arnau wrote:
Hi all,

I  have a hash of hashes in hiera:

cb_data_sync:
   localdata:
     peers: peer1 peer2
     source: /data/1
     target: /data/2
     ssh_key:
       key: XYZ
       type: ssh-rsa
       user: root

Then, in a main class, I call a define using the above data:

class cb_sync(
   Hash $cb_sync = lookup(cb_data_sync),
The lookup here has no effect - it will use APL to do exactly what the default expression is doing - thus, it will never be called.
(Not the source of your problem, but you can remove that call).

) {

   $cb_sync.each |$name, $data| {

Variable $name will shadow the meta parameter $name in the outer scope.
better to use a different variable name here. However, doubt this will cause the problem.

     cb_sync::rsync{ $name:
       data_sync => $data,
     }
   }

}

so far, so good.

cb_sync::rsync is a define and there I'd like to create a ssh_authorized_key from the ssh_key nested hash.

So, my code looks like:

define cb_sync::rsync (
   Hash $data_sync = undef,
) {

     ssh_authorized_key {
       "${name}-ssh_key":
         * => "${data_sync['ssh_key']}",

You are expecting 'ssh_key' to be a key. Your hiera data shows there is a "localdata" key under which there is a hash with that key.
So, you end up with an empty hash.

Also, you are using interpolation to interpolate a hash as a string.
That is not right. You probably want this:

* => $data_sync['localdata']['ssh_key']


       }
But puppet complains cause it says that it gets a string  but expects a Hash.

Well, you interpolated a hash into a string...

If I "notify" data_sync['ssh_key'] I get:

Notice: {key => XYZ, type => ssh-rsa, user => root}

ok, then maybe your hieradata above is not exactly what you are using?
If that key worked, change what I said you should use above and drop
the 'lokaldata' part.


(which looks like a hash to me,am I wrong?).

A hash in string form (printed) looks very much like a hash in source code form, but a Hash it was not.

- henrik



--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/pcuoa2%249ml%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to