Ask Your Question

has_key(): expects the first argument to be a hash, got String

asked 2017-01-12 10:42:24 -0600

hoggl gravatar image


I have troube understanding this maybe somebody can enlighten me:

A have written a custom fact(ruby) which stores a hash in the puppet facts hash.

The result looks like this:

filesystem_size => {"/"=>"1952", "/dev"=>"3891", "/dev/shm"=>"3904", "/run"=>"3904", "/sys/fs/cgroup"=>"3904", "/usr"=>"3904", "/boot"=>"2016", "/home"=>"976", "/opt"=>"1952", "/var"=>"1952", "/tmp"=>"1952", "/var/log"=>"1952", "/var/log/audit"=>"1952", "/mnt/boshare_live"=>"26211562", "/mnt/boshare_test"=>"403033", "/run/user/6331"=>"781", "/run/user/12001"=>"781"}

For me this looks good.

Then I want to use this values in my manifest like this:

  if has_key($facts['logical_volumes_size'],"lv_${target_lv}/${target_vg}") {
    # do something

I've also tried using parsejson but regardless what I do here I get the following error:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: {"message":"Server Error: Evaluation Error: Error while evaluating a Function Call, has_key(): expects the first argument to be a hash, got \"{\\\"lv_audit_lv/rootvg\\\"=>\\\"2097152\\\", \\\"lv_drbd_lv/rootvg\\\"=>\\\"157286400\\\", \\\"lv_home_lv/rootvg\\\"=>\\\"1048576\\\", \\\"lv_log_lv/rootvg\\\"=>\\\"2097152\\\", \\\"lv_opt_lv/rootvg\\\"=>\\\"5242880\\\", \\\"lv_slash_lv/rootvg\\\"=>\\\"2097152\\\", \\\"lv_swap_lv/rootvg\\\"=>\\\"6160384\\\", \\\"lv_tmp_lv/rootvg\\\"=>\\\"2097152\\\", \\\"lv_usr_lv/rootvg\\\"=>\\\"4194304\\\", \\\"lv_var_lv/rootvg\\\"=>\\\"4194304\\\"}\" which is of type String at /etc/puppetlabs/code/environments/testing/modules/drbd/manifests/init.pp:124:6 on node myhost","issue_kind":"RUNTIME_ERROR"}

Help is very much appreciated !

Thanks :-)

edit retag flag offensive close merge delete


Hi, It seems like logical_volumes_size is not a Hash, and I don't know if that was just a mistake, but the custom facts you discussed about was filesystem_size (which seem a valid hash), but in the manisfest, you are checking logical_volume_size (which indeed seems like a simple string.....)

stivesso gravatar imagestivesso ( 2017-01-13 01:20:18 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2017-01-13 14:31:25 -0600

lavaman gravatar image

You don't say what version of puppet you are using, but if you are using <4.0, I'm guessing you need to set stringify_facts to false in your puppet.conf

edit flag offensive delete link more

answered 2017-01-14 03:02:01 -0600

hoggl gravatar image

updated 2017-01-14 03:02:49 -0600

thanks for the reply.

sorry - I've mistakenly added the wrong facts hash.

Here is the correct one:

facter -p | grep logical logicalvolumessize => {"lvauditlv/rootvg"=>"2097152", "lvdrbdlv/rootvg"=>"157286400", "lvhomelv/rootvg"=>"1048576", "lvloglv/rootvg"=>"2097152", "lvoptlv/rootvg"=>"5242880", "lvslashlv/rootvg"=>"2097152", "lvswaplv/rootvg"=>"6160384", "lvtmplv/rootvg"=>"2097152", "lvusrlv/rootvg"=>"4194304", "lvvarlv/rootvg"=>"4194304"}

Indeed the issue was "stringify_facts". Setting this to false on the agent fixed the problem.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-01-12 10:42:24 -0600

Seen: 205 times

Last updated: Jan 14 '17