create_resources function returns error "can't convert Array into Hash"

1,790 views
Skip to first unread message

JeremyCampbell

unread,
Sep 5, 2012, 10:05:52 AM9/5/12
to puppet...@googlegroups.com
I have written a custom function that returns a hash of data to be used by the create_resources function.

class network::multiroute::mhpeers (
) {
  $routes = gen_ip_routes("gw.uk")
  create_resources(network::multiroute::mhpeer, $routes)
}

However, on the puppet client I get "err: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert Array into Hash"

My custom function returns the following data structure:

{"10.100.0.9"=>{"dstip"=>"10.100.0.10", "dsthost"=>"gw1.uk"}, "10.100.0.46"=>{"dstip"=>"10.100.0.45", "dsthost"=>"gw1.fr"}, "10.100.0.17"=>{"dstip"=>"10.100.0.18", "dsthost"=>"gw2.us"}, "10.100.0.13"=>{"dstip"=>"10.100.0.14", "dsthost"=>"gw1.us"}}

Based on the puppet source  the rdoc states:

The hash should be in the form `{title => {parameters} }`

I believe I am returning the hash in the correct format so I am confused as to what the problem could be. I've been stuck on this issue for quite some time, any pointers would be really appreciated!

Dan Bode

unread,
Sep 5, 2012, 10:15:02 AM9/5/12
to puppet...@googlegroups.com
On Wed, Sep 5, 2012 at 7:05 AM, JeremyCampbell <jeremyca...@gmail.com> wrote:
I have written a custom function that returns a hash of data to be used by the create_resources function.

class network::multiroute::mhpeers (
) {
  $routes = gen_ip_routes("gw.uk")
  create_resources(network::multiroute::mhpeer, $routes)
}

However, on the puppet client I get "err: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert Array into Hash"

can you try this with --trace and post the output?

also,can you put the following line before the call to create_resources just to verify the data structure?

$foo = inline_template("<% puts routes.inspect %>")

also, could you try quoting the name of the defined type?  'network::multiroute::mhpeer'

My custom function returns the following data structure:

{"10.100.0.9"=>{"dstip"=>"10.100.0.10", "dsthost"=>"gw1.uk"}, "10.100.0.46"=>{"dstip"=>"10.100.0.45", "dsthost"=>"gw1.fr"}, "10.100.0.17"=>{"dstip"=>"10.100.0.18", "dsthost"=>"gw2.us"}, "10.100.0.13"=>{"dstip"=>"10.100.0.14", "dsthost"=>"gw1.us"}}

Based on the puppet source  the rdoc states:

The hash should be in the form `{title => {parameters} }`

I believe I am returning the hash in the correct format so I am confused as to what the problem could be. I've been stuck on this issue for quite some time, any pointers would be really appreciated!

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/h4EyleCsPLsJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

JeremyCampbell

unread,
Sep 5, 2012, 11:15:53 AM9/5/12
to puppet...@googlegroups.com


On Wednesday, September 5, 2012 4:15:31 PM UTC+2, Dan Bode wrote:


On Wed, Sep 5, 2012 at 7:05 AM, JeremyCampbell <jeremyca...@gmail.com> wrote:
I have written a custom function that returns a hash of data to be used by the create_resources function.

class network::multiroute::mhpeers (
) {
  $routes = gen_ip_routes("gw.uk")
  create_resources(network::multiroute::mhpeer, $routes)
}

However, on the puppet client I get "err: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert Array into Hash"

can you try this with --trace and post the output?

# puppet agent --test --server devbox --trace
info: Retrieving plugin
info: Loading facts in /var/lib/puppet/lib/facter/defgw_ipv4.rb
info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
info: Loading facts in /var/lib/puppet/lib/facter/virtual.rb
info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/rest.rb:56:in `deserialize'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/rest.rb:126:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/indirection.rb:195:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:239:in `retrieve_new_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:493:in `thinmark'
/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:492:in `thinmark'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:238:in `retrieve_new_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:86:in `retrieve_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:112:in `retrieve_and_apply_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:152:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:43:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent/locker.rb:21:in `lock'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:43:in `run'
/usr/lib/ruby/1.8/sync.rb:230:in `synchronize'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:43:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:95:in `with_client'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:41:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:172:in `call'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:172:in `controlled_run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:39:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application/agent.rb:339:in `onetime'
/usr/lib/ruby/site_ruby/1.8/puppet/application/agent.rb:313:in `run_command'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:309:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:416:in `hook'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:309:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:407:in `exit_on_fail'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:309:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:69:in `execute'
/usr/bin/puppet:4
err: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert Array into Hash at /etc/puppet/puppet/modules/network/manifests/multiroute/mhpeers.pp:7 on node gw1.zz
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run

also,can you put the following line before the call to create_resources just to verify the data structure?

$foo = inline_template("<% puts routes.inspect %>")

I've done that but I'm not sure where/what output you expect. Please advise.

also, could you try quoting the name of the defined type?  'network::multiroute::mhpeer'

Ok, Ive done this, but it doesn't make any difference.

Dan Bode

unread,
Sep 5, 2012, 11:20:19 AM9/5/12
to puppet...@googlegroups.com
actually, I care way more about --trace on the master 


also,can you put the following line before the call to create_resources just to verify the data structure?

$foo = inline_template("<% puts routes.inspect %>")

I've done that but I'm not sure where/what output you expect. Please advise.

This should print the actual data structure in the masters logs. I would recommend just running the master from the foreground and looking for this output.
 

also, could you try quoting the name of the defined type?  'network::multiroute::mhpeer'

Ok, Ive done this, but it doesn't make any difference.

ok, it was worth a try, that would have been easy :)
 

My custom function returns the following data structure:

{"10.100.0.9"=>{"dstip"=>"10.100.0.10", "dsthost"=>"gw1.uk"}, "10.100.0.46"=>{"dstip"=>"10.100.0.45", "dsthost"=>"gw1.fr"}, "10.100.0.17"=>{"dstip"=>"10.100.0.18", "dsthost"=>"gw2.us"}, "10.100.0.13"=>{"dstip"=>"10.100.0.14", "dsthost"=>"gw1.us"}}

Based on the puppet source  the rdoc states:

The hash should be in the form `{title => {parameters} }`

I believe I am returning the hash in the correct format so I am confused as to what the problem could be. I've been stuck on this issue for quite some time, any pointers would be really appreciated!

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/h4EyleCsPLsJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/V4MvJx5TfXAJ.

JeremyCampbell

unread,
Sep 5, 2012, 11:37:43 AM9/5/12
to puppet...@googlegroups.com

Sorry Dan, I should have realized you meant on the master. See below - is this what you expected?

$ sudo /usr/sbin/puppetmasterd --no-daemonize --trace
{"10.100.0.10"=>{"dsthost"=>"gw1.nl", "dstip"=>"10.100.0.9"}, "10.100.0.34"=>{"dsthost"=>"gw1.fr", "dstip"=>"10.100.0.33"}, "10.100.0.6"=>{"dsthost"=>"gw2.us", "dstip"=>"10.100.0.5"}, "10.100.0.2"=>{"dsthost"=>"gw1.us", "dstip"=>"10.100.0.1"}, "10.100.0.22"=>{"dsthost"=>"gw2.nl", "dstip"=>"10.100.0.21"}}
 

Dan Bode

unread,
Sep 5, 2012, 11:42:36 AM9/5/12
to puppet...@googlegroups.com
yep, although it looks completely valid.

Can you share the result of --trace from the master?
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/QLYzDRNyhxEJ.

JeremyCampbell

unread,
Sep 8, 2012, 12:13:10 PM9/8/12
to puppet...@googlegroups.com

Hi Dan, I just wanted to apologize for not getting back to you sooner. I hacked away on the issue, triple checking everything, restarting the puppetmaster and eventually it just worked. I wish I knew what the problem was but alas I cannot figure it out. Regardless, I  wouldn't have managed to resolve it without your suggestions, so thank you!. Have a great weekend.
Reply all
Reply to author
Forward
0 new messages