How to get a value of fact that has dot in name?

768 views
Skip to first unread message

Jakov Sosic

unread,
Mar 17, 2016, 7:29:34 PM3/17/16
to Puppet Users
Hi guys,

I have interfaces bond0.2 and bond0.3 respectively (VLAN tagged).

How can I get IP address in hiera?


I've tried this:


myvar: "%{::networking.interfaces.bond0.2.ip}"


but it produces error:

SERVER: Internal Server Error: org.jruby.exceptions.RaiseException:
(Exception) Hiera type mismatch: Got Hash when Array was expected enable
lookup using key '2'



I've tried escaping with backslash, singlequoting, etc, but no luck..


Any ideas?

Jakov Sosic

unread,
Mar 17, 2016, 8:44:21 PM3/17/16
to Puppet Users
Even this is causing problems:

$ puppet apply -e 'notify { $::networking['interfaces']['bond0.2']['ip']: }'
Error: Could not parse for environment production: Syntax error at '2'
at line 1:42 on node xxx

Francois Lafont

unread,
Mar 18, 2016, 1:52:56 AM3/18/16
to puppet...@googlegroups.com
Hello,
In fact, it's currently impossible in hiera:

https://tickets.puppetlabs.com/browse/PUP-5990

According to the ticket, it should be solved in the next Puppet version,
ie Puppet 4.4.1.

Regards.
François Lafont

Francois Lafont

unread,
Mar 18, 2016, 1:59:15 AM3/18/16
to puppet...@googlegroups.com
On 18/03/2016 01:44, Jakov Sosic wrote:

> Even this is causing problems:
>
> $ puppet apply -e 'notify { $::networking['interfaces']['bond0.2']['ip']: }'
> Error: Could not parse for environment production: Syntax error at '2' at line 1:42 on node xxx

Normally, in puppet code, there is no problem. I think your command is
incorrect because you use simple quotes to delimit in the shell the value
of the -e option, and you use simple quotes inside the value too.

Furthermore, in my puppet version (ie 4.4.0), the subkeys to reach the
IP address are different from your example above. For me, this works well:

~# puppet apply -e 'notice ( $::networking["interfaces"]["bond0.24"]["bindings"][0]["address"] )'
Notice: Scope(Class[main]): 192.168.24.11
Notice: Compiled catalog for cargo01.dc2.backbone.education in environment production in 0.04 seconds
Notice: Applied catalog in 0.08 seconds

Regards.
François Lafont

jcbollinger

unread,
Mar 18, 2016, 10:03:05 AM3/18/16
to Puppet Users


On Thursday, March 17, 2016 at 6:29:34 PM UTC-5, Jakov Sosic wrote:
Hi guys,

I have interfaces bond0.2 and bond0.3 respectively (VLAN tagged).

How can I get IP address in hiera?


I've tried this:


myvar: "%{::networking.interfaces.bond0.2.ip}"


but it produces error:

SERVER: Internal Server Error: org.jruby.exceptions.RaiseException:
(Exception) Hiera type mismatch: Got Hash when Array was expected enable
lookup using key '2'



I had to read this question a few times to grasp what you are asking.  If there is a fact involved here at all, its name is apparently "interfaces", which has no dot in it.  Facts are exposed in Puppet DSL as variables, and Puppet variable names cannot contain dots.  I'm not sure what Puppet would do if you tried to feed it a fact whose name actually had a dot in it.  On the contrary, this appears to be about keys appearing in the value of a hash-valued fact.

My apologies for being pedantic, but we are all best served when we communicate clearly.



I've tried escaping with backslash, singlequoting, etc, but no luck..



François seems to have a promising suggestion.  In any event, he is quite right that the "puppet apply" command you presented doesn't mean quite what you probably thought it meant.


John



Jakov Sosic

unread,
Mar 18, 2016, 6:24:10 PM3/18/16
to puppet...@googlegroups.com
On 03/18/2016 06:52 AM, Francois Lafont wrote:

> In fact, it's currently impossible in hiera:
>
> https://tickets.puppetlabs.com/browse/PUP-5990
>
> According to the ticket, it should be solved in the next Puppet version,
> ie Puppet 4.4.1.

Oh wow, it is addressed! Thanks! :)

Jakov Sosic

unread,
Mar 18, 2016, 6:24:27 PM3/18/16
to puppet...@googlegroups.com
Huh, my mistake. That's what happens when you clock in long hours :)

Henrik Lindberg

unread,
Mar 18, 2016, 9:25:03 PM3/18/16
to puppet...@googlegroups.com
Correct, In 4.4.1 it is possible to quote the entire key, or parts of
the key. This will work with both lookup and classic Hiera both when
performing the "top level" lookup and in interpolations inside hiera data.

- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
Reply all
Reply to author
Forward
0 new messages