Data Type: Hashes

929 views
Skip to first unread message

Matthew Ceroni

unread,
Nov 24, 2015, 7:36:09 PM11/24/15
to puppet...@googlegroups.com
I am having an issue accessing elements of a hash.

First, it is defined in hiera as such:

lb::rules:
  VCC: rule1
  GR: rule2

I retrieve the value using

$lb_rules = hiera('lb::rules')

Then I simply try to print out one of the values
ex:

     notify { "$lb_rules[VCC]": }

But get 

Error 400 on SERVER: Evaluation Error: Missing title. The title expression resulted in undef at /etc/puppet/environments/sandbox/manifests/site.pp:14:11

If I don't specify a key and instead do

notify { "$lb_rules": }

I get 

Error 400 on SERVER: Evaluation Error: Illegal title type at index 0. Expected String, got Hash[String, String]

Confirming that lb_rules is a hash.




Peter Huene

unread,
Nov 24, 2015, 7:41:10 PM11/24/15
to puppet...@googlegroups.com
Hi Matthew,

On Tue, Nov 24, 2015 at 4:35 PM, Matthew Ceroni <matthe...@gmail.com> wrote:
I am having an issue accessing elements of a hash.

First, it is defined in hiera as such:

lb::rules:
  VCC: rule1
  GR: rule2

I retrieve the value using

$lb_rules = hiera('lb::rules')

Then I simply try to print out one of the values
ex:

     notify { "$lb_rules[VCC]": }

VCC (without quotes) is a type name in the Puppet Language because it starts with a capitalized letter.

Try using single quotes around VCC, like so: 

```
notify { "$lb_rules['VCC']": }
```
 

But get 

Error 400 on SERVER: Evaluation Error: Missing title. The title expression resulted in undef at /etc/puppet/environments/sandbox/manifests/site.pp:14:11

If I don't specify a key and instead do

notify { "$lb_rules": }

I get 

Error 400 on SERVER: Evaluation Error: Illegal title type at index 0. Expected String, got Hash[String, String]

Confirming that lb_rules is a hash.




--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CA%2BNsY5jkQAEyamw7yauG2FWA6ktqeWGOVRZBCKaS_pW%2BYqS0OQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
Nov 25, 2015, 9:33:35 AM11/25/15
to Puppet Users


I've found that it's always a good idea to use the ${} form when you interpolate a value into a string.  Sometimes you don't actually need it, but sometimes you do, and it's just easier to do it all the time.  Thus,

notify { "${lb_rules[VCC]}": }

or, even better,

notify { "${lb_rules['VCC']}": }


John

Henrik Lindberg

unread,
Nov 27, 2015, 11:27:37 AM11/27/15
to puppet...@googlegroups.com
On 2015-25-11 1:35, Matthew Ceroni wrote:
> I am having an issue accessing elements of a hash.
>
> First, it is defined in hiera as such:
>
> lb::rules:
> VCC: rule1
> GR: rule2
>
> I retrieve the value using
>
> $lb_rules = hiera('lb::rules')
>
> Then I simply try to print out one of the values
> ex:
>
> notify { "$lb_rules[VCC]": }
>

To interpolate the [] expression you must write
"${lb_rules['VLC']}"

Otherwise the [] part becomes text. You must quote the uppercase bare
word or it will be interpreted as the name of a type (like Integer, or
File).

Since you ended up with the [] part in your title, and because puppet to
bat crazy stuff with titles containing them (in some versions of
puppet), you end up with the error you got.

Hope that helps.

- henrik

> But get
>
> Error 400 on SERVER: Evaluation Error: Missing title. The title
> expression resulted in undef at
> /etc/puppet/environments/sandbox/manifests/site.pp:14:11
>
> If I don't specify a key and instead do
>
> notify { "$lb_rules": }
>
> I get
>
> Error 400 on SERVER: Evaluation Error: Illegal title type at index 0.
> Expected String, got Hash[String, String]
>
> Confirming that lb_rules is a hash.
>
>
>
>
> --
> 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>.
> <https://groups.google.com/d/msgid/puppet-users/CA%2BNsY5jkQAEyamw7yauG2FWA6ktqeWGOVRZBCKaS_pW%2BYqS0OQ%40mail.gmail.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/

Reply all
Reply to author
Forward
0 new messages