YAML as File resource template Error , "can't convert Hash to String"

169 views
Skip to first unread message

treydock

unread,
Dec 10, 2012, 3:35:49 PM12/10/12
to puppet...@googlegroups.com
Using exported resources I'm trying to have a host export a File resource generated from a yaml template, to another host.  The host that gets the exported resource is throwing errors like this

err: Failed to apply catalog: Parameter content failed: Munging failed for value {"parameters"=>{"macaddress_p2p1"=>"00:15:17:80:5A:3E", "macaddress_p2p2"=>"00:15:17:80:5A:3F", "macaddress_eth0"=>"00:1E:C9:55:12:C7", "macaddress_eth1"=>"00:1E:C9:55:12:C9", "operatingsystem"=>"CentOS", "serialnumber"=>"", "interfaces"=>"eth0,eth1,lo,p2p1,p2p2", "fqdn"=>"<snip>", "ipaddress_p2p1"=>"", "ipaddress_p2p2"=>"", "uuid"=>"", "ipaddress_eth0"=>"", "ipaddress_eth1"=>"<snip>", "productname"=>"", "operatingsystemrelease"=>"6.3"}, "name"=>"<snip>"} in class content: can't convert Hash into String

Here is the parts of the module...

class racktables::export (
  $site,
  $yamls_dir  = 'UNSET'
) inherits racktables::params {

  $yamls_dir_REAL = $yamls_dir ? {
    'UNSET'   => "${conf_dir}/${site}/yamls",
    default   => $yamls_dir,
  }

  @@file { "racktables_host_${::hostname}.yaml":
    content   => template('racktables/host.yaml.erb'),
    path      => "${yamls_dir_REAL}/${::hostname}.yaml",
    tag       => "host_yaml_for_${site}",
  }

}

define racktables::instance (
...
) {
<snip>

  File <<| tag == "host_yaml_for_${name}" |>> {
    require   => File[$yaml_exports_REAL],
  }

<snip>
}

Template...

# cat templates/host.yaml.erb
--- 
name: "<%= scope.lookupvar('::hostname') %>"
parameters: 
  interfaces: "<%= scope.lookupvar('::interfaces') %>"
  fqdn: "<%= scope.lookupvar('::fqdn') %>"
  operatingsystemrelease: "<%= scope.lookupvar('::operatingsystemrelease') %>"
  operatingsystem: "<%= scope.lookupvar('::operatingsystem') %>"
  productname: ""
  uuid: ""
  serialnumber: ""
<% scope.lookupvar('::interfaces').split(',').each do |interface| -%>
<% unless interface.eql? "lo" -%>
  ipaddress_<%= interface %>: "<%= scope.lookupvar("::ipaddress_#{interface}") %>"
  macaddress_<%= interface %>: "<%= scope.lookupvar("::macaddress_#{interface}") %>"
<% end -%>
<% end -%>


Is there some catch to using a YAML file for the template content?  Would it be better to use Ruby DSL for the racktables::export class and generate a hash -> sort -> to_yaml and have that be set as the content?

Thanks
- Trey
Reply all
Reply to author
Forward
0 new messages