Klavs Klavsen
2013-May-08 14:22 UTC
[Puppet Users] define and exported resources - giving wrong template content
Hi, I have an odd problem - I have a define, as an exported resource. when puppet creates them on the central gdash host - it creates them with the correct (client) hostname (f.ex. cat /var/www/gdash/graph_templates/dashboards/hosts/p-web01/dash.yaml) - but the content has the central gdash hostname in them instead (of f.ex. p-web01 etc.). I do the same with nagios config - and there it works fine (only diff I can see, is that I do export the file resource directly (with a tag), instead of doing it in a define). ##definition - run on hosts @@gdash::hostgraphs { "${::hostname}": } ##profile on gdash server Gdash::Hostgraphs <<| |>> { } ##gdash::hostgraphs define gdash::hostgraphs () { $tplpath = "/var/www/gdash/graph_templates/dashboards" $hostpath = "$tplpath/hosts/$name" #file { "$tplpath/hosts": ensure => directory } file { "$tplpath/hosts/$name": ensure => directory, require => File["$tplpath/hosts"] } #$graphs = [ ''dash.yaml'', ''cpu.graph'', ''io.graph'', ''iops.graph'', ''load.graph'', ''memory.graph'', ''nettraf.graph'', ''sockets.graph''] file { "$hostpath/dash.yaml": content => template(''gdash/dash.yaml'') } file { "$hostpath/cpu.graph": content => template(''gdash/cpu.graph'') } file { "$hostpath/io.graph": content => template(''gdash/io.graph'') } file { "$hostpath/iops.graph": content => template(''gdash/iops.graph'') } file { "$hostpath/load.graph": content => template(''gdash/load.graph'') } file { "$hostpath/memory.graph": content => template(''gdash/memory.graph'') } file { "$hostpath/nettraf.graph": content => template(''gdash/nettraf.graph'') } file { "$hostpath/sockets.graph": content => template(''gdash/sockets.graph'') } } The templates all look kinda like this (modules/gdash/templates/dash.yaml): :name: <%= hostname %> :description: Graphs for <%= fqdn %> Anyone have any ideas? It''s puppet v3.1.1 -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-May-08 19:57 UTC
[Puppet Users] Re: define and exported resources - giving wrong template content
On Wednesday, May 8, 2013 9:22:16 AM UTC-5, Klavs Klavsen wrote:> > Hi, > > I have an odd problem - I have a define, as an exported resource. when > puppet creates them on the central gdash host - it creates them with the > correct (client) hostname (f.ex. cat > /var/www/gdash/graph_templates/dashboards/hosts/p-web01/dash.yaml) - but > the content has the central gdash hostname in them instead (of f.ex. > p-web01 etc.). > > I do the same with nagios config - and there it works fine (only diff I > can see, is that I do export the file resource directly (with a tag), > instead of doing it in a define). > > ##definition - run on hosts > @@gdash::hostgraphs { "${::hostname}": } > > ##profile on gdash server > Gdash::Hostgraphs <<| |>> { } > > ##gdash::hostgraphs > > define gdash::hostgraphs () { > $tplpath = "/var/www/gdash/graph_templates/dashboards" > $hostpath = "$tplpath/hosts/$name" > #file { "$tplpath/hosts": ensure => directory } > file { "$tplpath/hosts/$name": ensure => directory, require => > File["$tplpath/hosts"] } > #$graphs = [ ''dash.yaml'', ''cpu.graph'', ''io.graph'', ''iops.graph'', > ''load.graph'', ''memory.graph'', ''nettraf.graph'', ''sockets.graph''] > file { "$hostpath/dash.yaml": content => template(''gdash/dash.yaml'') } > file { "$hostpath/cpu.graph": content => template(''gdash/cpu.graph'') } > file { "$hostpath/io.graph": content => template(''gdash/io.graph'') } > file { "$hostpath/iops.graph": content => template(''gdash/iops.graph'') } > file { "$hostpath/load.graph": content => template(''gdash/load.graph'') } > file { "$hostpath/memory.graph": content => > template(''gdash/memory.graph'') } > file { "$hostpath/nettraf.graph": content => > template(''gdash/nettraf.graph'') } > file { "$hostpath/sockets.graph": content => > template(''gdash/sockets.graph'') } > } > > The templates all look kinda like this (modules/gdash/templates/dash.yaml): > :name: <%= hostname %> > :description: Graphs for <%= fqdn %> > > Anyone have any ideas? > > It''s puppet v3.1.1 > >I''m not sure I would have predicted the behavior you see, but it makes sense. When you export a resource you are exporting the resource type and parameters. When you later import that resource, it is evaluated in the context of the importing host, just as you see. Evidently, if you want to convey data from the exporter to the importer then it must be carried by parameters of the exported resource. John -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
joe
2013-May-08 22:30 UTC
[Puppet Users] Re: define and exported resources - giving wrong template content
jcbollinger is correct. Templates are evaluated on the master in response to a catalog request. Any facter values used in the template will be the values from the host requesting the catalog. In your nagios module, you export the file resource (with it''s contents) from the server with the correct values. This is because the resource is *evaluated* on the client run and then exported. In your defined type, you are not actually evaluating the template contents because you wrap it in a defined type. This means the resources in the defined type are exported from the client, but not evaluated until the server requests its catalog. So you end up with values from the server instead of the client. On Wednesday, May 8, 2013 1:57:05 PM UTC-6, jcbollinger wrote:> > > > On Wednesday, May 8, 2013 9:22:16 AM UTC-5, Klavs Klavsen wrote: >> >> Hi, >> >> I have an odd problem - I have a define, as an exported resource. when >> puppet creates them on the central gdash host - it creates them with the >> correct (client) hostname (f.ex. cat >> /var/www/gdash/graph_templates/dashboards/hosts/p-web01/dash.yaml) - but >> the content has the central gdash hostname in them instead (of f.ex. >> p-web01 etc.). >> >> I do the same with nagios config - and there it works fine (only diff I >> can see, is that I do export the file resource directly (with a tag), >> instead of doing it in a define). >> >> ##definition - run on hosts >> @@gdash::hostgraphs { "${::hostname}": } >> >> ##profile on gdash server >> Gdash::Hostgraphs <<| |>> { } >> >> ##gdash::hostgraphs >> >> define gdash::hostgraphs () { >> $tplpath = "/var/www/gdash/graph_templates/dashboards" >> $hostpath = "$tplpath/hosts/$name" >> #file { "$tplpath/hosts": ensure => directory } >> file { "$tplpath/hosts/$name": ensure => directory, require => >> File["$tplpath/hosts"] } >> #$graphs = [ ''dash.yaml'', ''cpu.graph'', ''io.graph'', ''iops.graph'', >> ''load.graph'', ''memory.graph'', ''nettraf.graph'', ''sockets.graph''] >> file { "$hostpath/dash.yaml": content => template(''gdash/dash.yaml'') } >> file { "$hostpath/cpu.graph": content => template(''gdash/cpu.graph'') } >> file { "$hostpath/io.graph": content => template(''gdash/io.graph'') } >> file { "$hostpath/iops.graph": content => template(''gdash/iops.graph'') } >> file { "$hostpath/load.graph": content => template(''gdash/load.graph'') } >> file { "$hostpath/memory.graph": content => >> template(''gdash/memory.graph'') } >> file { "$hostpath/nettraf.graph": content => >> template(''gdash/nettraf.graph'') } >> file { "$hostpath/sockets.graph": content => >> template(''gdash/sockets.graph'') } >> } >> >> The templates all look kinda like this >> (modules/gdash/templates/dash.yaml): >> :name: <%= hostname %> >> :description: Graphs for <%= fqdn %> >> >> Anyone have any ideas? >> >> It''s puppet v3.1.1 >> >> > > I''m not sure I would have predicted the behavior you see, but it makes > sense. When you export a resource you are exporting the resource type and > parameters. When you later import that resource, it is evaluated in the > context of the importing host, just as you see. Evidently, if you want to > convey data from the exporter to the importer then it must be carried by > parameters of the exported resource. > > > John > >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.