Hey, recently I wrote my first custom type. It''s a rather easy one, that should only create a config file if it is inconsistent. The config file is for another tool that creates virtual network interfaces and assigns IP addresses to them (used for loadbalancing). Basically it looks like this: IFACE1="lo:0" IP1="192.168.0.10" IFACE2="lo:1" IP2="192.168.98.34" IFACE3="lo:2" IP3="192.168.2.204" the custom type gets the ip addresses as a string looking like this: $ipstringA = "192.168.0.10 192.168.98.34" $ipstringB = "192.168.2.204" The type is defined like this: ###start### require ''resolv'' module Puppet newtype(:balanceclient) do @doc = "Creates client.conf" newparam(:ips) do desc "The IP address(es) that need to be set in the client.conf." end newparam(:target) do desc "The filename" isnamevar end newproperty(:ensure) do desc "Whether the resource is in sync or not." defaultto :insync def retrieve ips = resource[:ips].split('' '').uniq c = 0 ac = 0 File.readlines(resource[:target]).each { |l| if l.include?("# Hostname: ") c=c+1 end ips.each { |a| if l.include?("#{a}") ac=ac+1 end } } if c.eql?(ips.length) && ac.eql?(ips.length) :insync else :outofsync end end newvalue :outofsync newvalue :insync do output = File.open(resource[:target], "w") ips = resource[:ips].split('' '').uniq output.puts "# Diese Datei wird durch Puppet verwaltet, manuelle Aenderungen werden ueberschrieben.\n# This file is managed by puppet - modifications will be overwritten.\n\n" 1.upto(ips.length) do |x| iaddr = ips[x-1] if hn = Resolv::DNS.new.getname("#{iaddr}") else if hn.length <= 0 hn = ips[x-1]; end end output.puts "# Hostname: #{hn}\n"; output.puts "IFACE#{x}\=\"lo:#{x-1}\"\n"; output.puts "IP#{x}\=\"#{ips[x-1]}\"\n\n"; end end end end end ###end### and it is called from a std class: ###start### class testclass { balanceclient { "balclient": target => "/path/to/client.conf", ensure => insync, ips => $hosttype ? { "type1" => $ipstringB, "type2" => "$ipstringA $ipstringB", default => "", }, } } ###end### now ... what I experience is: * running "puppet -dv testclass" on the server went fine. File is written, updated, and left alone if everything is insync. * deploying the type and running puppetd on a node that is including this class from a second one, it doesn''t. Puppet just does nothing regarding this class and type - everything else seems to be working. Did I do something wrong? Have I forgotten a vital element in this type? Why isn''t there a hint in "Pulling strings with puppet"? ;-) (Btw: great book, thanks for writing it, James!) Yours, Phillip
Phillip Scholz
2008-Jun-13 12:09 UTC
[Puppet Users] Re: Custom type not working with puppetd
Hey, it''s me again. I would be glad about nearly every hint. Phillip Phillip Scholz schrieb:> Hey, > > recently I wrote my first custom type. > > It''s a rather easy one, that should only create a config file if it is > inconsistent. > > The config file is for another tool that creates virtual network > interfaces and assigns IP addresses to them (used for loadbalancing). > > Basically it looks like this: > > IFACE1="lo:0" > IP1="192.168.0.10" > IFACE2="lo:1" > IP2="192.168.98.34" > IFACE3="lo:2" > IP3="192.168.2.204" > > the custom type gets the ip addresses as a string looking like this: > $ipstringA = "192.168.0.10 192.168.98.34" > $ipstringB = "192.168.2.204" > > The type is defined like this: > > ###start### > require ''resolv'' > > module Puppet > newtype(:balanceclient) do > @doc = "Creates client.conf" > > newparam(:ips) do > desc "The IP address(es) that need to be set in the client.conf." > end > > newparam(:target) do > desc "The filename" > isnamevar > end > > newproperty(:ensure) do > desc "Whether the resource is in sync or not." > > defaultto :insync > > def retrieve > ips = resource[:ips].split('' '').uniq > c = 0 > ac = 0 > > > File.readlines(resource[:target]).each { |l| > if l.include?("# Hostname: ") > c=c+1 > end > ips.each { |a| > if l.include?("#{a}") > ac=ac+1 > end > } > } > > > if c.eql?(ips.length) && ac.eql?(ips.length) > :insync > else > :outofsync > end > end > > newvalue :outofsync > newvalue :insync do > > output = File.open(resource[:target], "w") > > ips = resource[:ips].split('' '').uniq > > output.puts "# Diese Datei wird durch Puppet verwaltet, manuelle > Aenderungen werden ueberschrieben.\n# This file is managed by puppet - > modifications will be overwritten.\n\n" > > 1.upto(ips.length) do |x| > iaddr = ips[x-1] > if hn = Resolv::DNS.new.getname("#{iaddr}") > else > if hn.length <= 0 > hn = ips[x-1]; > end > end > output.puts "# Hostname: #{hn}\n"; > output.puts "IFACE#{x}\=\"lo:#{x-1}\"\n"; > output.puts "IP#{x}\=\"#{ips[x-1]}\"\n\n"; > end > > end > end > > end > end > ###end### > > and it is called from a std class: > > ###start### > class testclass { > > balanceclient { "balclient": > target => "/path/to/client.conf", > ensure => insync, > ips => $hosttype ? { > "type1" => $ipstringB, > "type2" => "$ipstringA $ipstringB", > default => "", > }, > } > } > ###end### > > > now ... what I experience is: > > * running "puppet -dv testclass" on the server went fine. File is > written, updated, and left alone if everything is insync. > > * deploying the type and running puppetd on a node that is including > this class from a second one, it doesn''t. Puppet just does nothing > regarding this class and type - everything else seems to be working. > > > Did I do something wrong? Have I forgotten a vital element in this type? > Why isn''t there a hint in "Pulling strings with puppet"? ;-) > (Btw: great book, thanks for writing it, James!) > > Yours, > Phillip >--
On Jun 11, 2008, at 10:24 AM, Phillip Scholz wrote:> [...] > now ... what I experience is: > > * running "puppet -dv testclass" on the server went fine. File is > written, updated, and left alone if everything is insync. > > * deploying the type and running puppetd on a node that is including > this class from a second one, it doesn''t. Puppet just does nothing > regarding this class and type - everything else seems to be working.If it works stand-alone but not with puppetd, then it''s just a problem in the setup, not in the resource type itself. It''s just doing nothing? I''d expect it to either work, or throw an exception about a missing resource type. Are you copying the resource type to the client, using pluginsync? Are you sure the resource isn''t already in sync? -- The salesman asked me what size I wore, I told him extra-medium. -- Stephen Wright --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Scholz
2008-Jun-13 16:06 UTC
[Puppet Users] Re: Custom type not working with puppetd
hey luke, happy to read from you. Luke Kanies schrieb:> If it works stand-alone but not with puppetd, then it''s just a problem > in the setup, not in the resource type itself. > > It''s just doing nothing?Nope, not even if I add "--debug --trace --verbose" to puppetd - well there is a lot of output there then - since every other class works and all ressources are compiled correctly, but not this one. The only occurance of the ressource name balanceclient is within a require.> I''d expect it to either work, or throw an > exception about a missing resource type. Are you copying the resource > type to the client, using pluginsync?Yes I do - and it is where it should be: # find /var/lib/puppet/ -type f -name ''*balanceclient*'' /var/lib/puppet/lib/balanceclient.rb> Are you sure the resource isn''t > already in sync?pretty sure - tried it with an empty file, without any file, with junk in the file, with the file being not completely created, and so on. Now, I tried to include the class to another class and I even added it directly to classes list in external nodes config. Phillip
Paul Lathrop
2008-Jun-13 17:22 UTC
[Puppet Users] Re: Custom type not working with puppetd
On Fri, Jun 13, 2008 at 9:06 AM, Phillip Scholz <phillip.scholz@1und1.de> wrote:> hey luke, > > happy to read from you. > > Luke Kanies schrieb: >> >> If it works stand-alone but not with puppetd, then it''s just a problem in >> the setup, not in the resource type itself. >> >> It''s just doing nothing? > > Nope, not even if I add "--debug --trace --verbose" to puppetd - well there > is a lot of output there then - since every other class works and all > ressources are compiled correctly, but not this one. The only occurance of > the ressource name balanceclient is within a require. > >> I''d expect it to either work, or throw an exception about a missing >> resource type. Are you copying the resource type to the client, using >> pluginsync? > > Yes I do - and it is where it should be: > > # find /var/lib/puppet/ -type f -name ''*balanceclient*'' > /var/lib/puppet/lib/balanceclient.rbHuh. Not sure if this is the case for you, but for me that path would need to be /var/lib/puppet/lib/puppet/balanceclient.rb (note the extra "puppet") HTH -Paul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Scholz
2008-Jun-16 09:19 UTC
[Puppet Users] Re: Custom type not working with puppetd
Paul Lathrop schrieb: >> # find /var/lib/puppet/ -type f -name ''*balanceclient*'' >> /var/lib/puppet/lib/balanceclient.rb > > Huh. Not sure if this is the case for you, but for me that path would > need to be /var/lib/puppet/lib/puppet/balanceclient.rb (note the extra > "puppet") > > HTH > -Paul Are you sure? this is my puppet.conf on the clients: [main] logdir=/var/log/puppet vardir=/var/lib/puppet ssldir=/var/lib/puppet/ssl rundir=/var/run/puppet factpath=$vardir/lib/facter pluginsync=true server=puppet.server.local libdir=$vardir/lib pluginsource=puppet://$server/plugins plugindest=$libdir [puppetmasterd] templatedir=/var/lib/puppet/templates
Phillip Scholz
2008-Jun-16 13:42 UTC
[Puppet Users] Re: Custom type not working with puppetd
Ok, I tried it: notice: /File[/var/lib/puppet/lib/puppet]/ensure: created notice: /File[/var/lib/puppet/lib/puppet/balanceclient.rb]/ensure: created but anyway - this would not be executed. I am a bit at a loss. More suggestions what to try? Paul Lathrop schrieb:> On Fri, Jun 13, 2008 at 9:06 AM, Phillip Scholz <phillip.scholz@1und1.de> wrote: >> hey luke, >> >> happy to read from you. >> >> Luke Kanies schrieb: >>> If it works stand-alone but not with puppetd, then it''s just a problem in >>> the setup, not in the resource type itself. >>> >>> It''s just doing nothing? >> Nope, not even if I add "--debug --trace --verbose" to puppetd - well there >> is a lot of output there then - since every other class works and all >> ressources are compiled correctly, but not this one. The only occurance of >> the ressource name balanceclient is within a require. >> >>> I''d expect it to either work, or throw an exception about a missing >>> resource type. Are you copying the resource type to the client, using >>> pluginsync? >> Yes I do - and it is where it should be: >> >> # find /var/lib/puppet/ -type f -name ''*balanceclient*'' >> /var/lib/puppet/lib/balanceclient.rb > > Huh. Not sure if this is the case for you, but for me that path would > need to be /var/lib/puppet/lib/puppet/balanceclient.rb (note the extra > "puppet") > > HTH > -Paul > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com > To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en > -~----------~----~----~----~------~----~------~--~--- > >--
Phillip Scholz
2008-Jun-16 14:11 UTC
[Puppet Users] *FIXED* [Puppet Users] Custom type not working with puppetd
got it - strace was my friend *doh* basically paul has been on the right path, but this file had to be in ${libdir}/puppet/type/ and on the server to get synced correctly: ${plugindir}/puppet/type/ thanks to all of you. Phillip Scholz schrieb:> Hey, > > recently I wrote my first custom type. > > It''s a rather easy one, that should only create a config file if it is > inconsistent. > > The config file is for another tool that creates virtual network > interfaces and assigns IP addresses to them (used for loadbalancing). > > Basically it looks like this: > > IFACE1="lo:0" > IP1="192.168.0.10" > IFACE2="lo:1" > IP2="192.168.98.34" > IFACE3="lo:2" > IP3="192.168.2.204" > > the custom type gets the ip addresses as a string looking like this: > $ipstringA = "192.168.0.10 192.168.98.34" > $ipstringB = "192.168.2.204" > > The type is defined like this: > > ###start### > require ''resolv'' > > module Puppet > newtype(:balanceclient) do > @doc = "Creates client.conf" > > newparam(:ips) do > desc "The IP address(es) that need to be set in the client.conf." > end > > newparam(:target) do > desc "The filename" > isnamevar > end > > newproperty(:ensure) do > desc "Whether the resource is in sync or not." > > defaultto :insync > > def retrieve > ips = resource[:ips].split('' '').uniq > c = 0 > ac = 0 > > > File.readlines(resource[:target]).each { |l| > if l.include?("# Hostname: ") > c=c+1 > end > ips.each { |a| > if l.include?("#{a}") > ac=ac+1 > end > } > } > > > if c.eql?(ips.length) && ac.eql?(ips.length) > :insync > else > :outofsync > end > end > > newvalue :outofsync > newvalue :insync do > > output = File.open(resource[:target], "w") > > ips = resource[:ips].split('' '').uniq > > output.puts "# Diese Datei wird durch Puppet verwaltet, manuelle > Aenderungen werden ueberschrieben.\n# This file is managed by puppet - > modifications will be overwritten.\n\n" > > 1.upto(ips.length) do |x| > iaddr = ips[x-1] > if hn = Resolv::DNS.new.getname("#{iaddr}") > else > if hn.length <= 0 > hn = ips[x-1]; > end > end > output.puts "# Hostname: #{hn}\n"; > output.puts "IFACE#{x}\=\"lo:#{x-1}\"\n"; > output.puts "IP#{x}\=\"#{ips[x-1]}\"\n\n"; > end > > end > end > > end > end > ###end### > > and it is called from a std class: > > ###start### > class testclass { > > balanceclient { "balclient": > target => "/path/to/client.conf", > ensure => insync, > ips => $hosttype ? { > "type1" => $ipstringB, > "type2" => "$ipstringA $ipstringB", > default => "", > }, > } > } > ###end### > > > now ... what I experience is: > > * running "puppet -dv testclass" on the server went fine. File is > written, updated, and left alone if everything is insync. > > * deploying the type and running puppetd on a node that is including > this class from a second one, it doesn''t. Puppet just does nothing > regarding this class and type - everything else seems to be working. > > > Did I do something wrong? Have I forgotten a vital element in this type? > Why isn''t there a hint in "Pulling strings with puppet"? ;-) > (Btw: great book, thanks for writing it, James!) > > Yours, > Phillip >--