Puppet Hiera Hash SubKey Interpolation

瀏覽次數:413 次
跳到第一則未讀訊息

Manoj Kumar

未讀,
2016年4月27日 上午8:47:202016/4/27
收件者:Puppet Users
Hi All,

Can you guys please help me to get the hiera hash subkey value in yaml files?

What I have in exec.yaml

talend::exec_mount_points:
    dataloading2:
        ad_user : 'user123'
        ad_password: 'test123'
        ad_domain: ''
        creds_file: 'passfile'
        mount_source: '//SOME-IP/data'
        mount_point: '/media'
        mount_options: "uid=edmadmin,gid=sftp-only,credentials=%{hiera('talend::creds_base_dir')}/.%{hiera('talend::exec_mount_points::dataloading2::creds_file')},defaults,sec=ntlm"
        mount_ensure: 'mounted'
        onboot: true
        fs_type: 'cifs'


I need to get the value from the above hash to use in its Subkey (creds_file) value like in mount_options: %{hiera('talend::exec_mount_points::dataloading2::creds_file')}

But I am getting nil/blank value. Can anyone suggest on this please

Aaron Russell

未讀,
2016年4月27日 上午9:05:272016/4/27
收件者:Puppet Users
I am not sure if you can lookup a subkey like that in hiera. (i could be wrong)

But this is how i do something similar. 

I do a hiera lookup for the hash in the class

$mount_points=hiera('talend::exec_mount_points')

Then i pull out all the keys

$mount_points_keys = keys($mount_points)

Then using the keys you can lookup subkeys in the hash

$creds_file_1=$mount_points[$mount_points_keys][creds_file]

Thanks

Henrik Lindberg

未讀,
2016年4月27日 晚上10:43:202016/4/27
收件者:puppet...@googlegroups.com
On 27/04/16 15:05, Aaron Russell wrote:
> I am not sure if you can lookup a subkey like that in hiera. (i could be
> wrong)
>

In later versions of puppet/hiera, it is possible to use dot (.)
notation to lookup a value within the data that is produced by they key.
It is possible to use both strings and numbers (for arrays).

For example:

talend::exec_mount_points.dataloading2.creds_file

A dot is not allowed as being part of the key. Again, later versions
will allow escaping parts of a key that contains dot by enclosing that
part in quotes.

- henrik

> But this is how i do something similar.
>
> I do a hiera lookup for the hash in the class
>
> $mount_points=hiera('talend::exec_mount_points')
>
> Then i pull out all the keys
>
> $mount_points_keys = keys($mount_points)
>
> Then using the keys you can lookup subkeys in the hash
>
> $creds_file_1=$mount_points[$mount_points_keys][creds_file]
>
> Thanks
>
> On Wednesday, April 27, 2016 at 8:47:20 AM UTC-4, Manoj Kumar wrote:
>
> Hi All,
>
> Can you guys please help me to get the hiera hash subkey value in
> yaml files?
>
> What I have in exec.yaml
>
> talend::*exec_mount_points:*
> dataloading2:
> ad_user : 'user123'
> ad_password: 'test123'
> ad_domain: ''
> creds_file: 'passfile'
> mount_source: '//SOME-IP/data'
> mount_point: '/media'
> mount_options:
> "uid=edmadmin,gid=sftp-only,credentials=%{hiera('talend::creds_base_dir')}/.*%{hiera('talend::exec_mount_points::dataloading2::creds_file')}*,defaults,sec=ntlm"
> mount_ensure: 'mounted'
> onboot: true
> fs_type: 'cifs'
>
>
> I need to get the value from the above hash to use in its S*ubkey
> (creds_file) value *like in
> mount_options: *%{hiera('talend::exec_mount_points::dataloading2::creds_file')}*
> *
> *
> But I am getting nil/blank value. Can anyone suggest on this please
>
> --
> 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...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/170f097d-430f-4b34-a71e-a3c1711aa477%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/170f097d-430f-4b34-a71e-a3c1711aa477%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
回覆所有人
回覆作者
轉寄
0 則新訊息