I''ve been using Puppet now for a month or so and I''ve come to a problem that may warrant an additional Puppet metaparameter. I''m advocating the addition of a metaparameter called "preaction" (or something like that), which will perform some arbitrary action before the resource is modified. There may be a way to do this within Puppet already (with some carefully crafted dependencies, auxiliary files, and an exec resource with an onlyif parameter). In the end, this feels like a complicated workaround, and seems to me that before/ require/subscribe/notify won''t cut it. The problem: With some PC hardware, the Linux kernel''s enumeration of ethernet device instances doesn''t match the hardware''s understanding of which ethernet card is first. For example, using Fedora 6 on a Dell 1950, eth0 corresponds to the onboard ethernet port labeled "2", and eth1 corresponds to the onboard ethernet port labeled "1". This is described in detail at http://linux.dell.com/files/whitepapers/nic- enum-whitepaper-v3.pdf . Luckily, this is fixable using Red Hat''s HWADDR sysconfig hack, and I implement this HWADDR fix with Puppet. Puppet writes /etc/sysconfig/network/ifcfg-eth0 and /etc/sysconfig/ network/ifcfg-eth1 using a Puppet definition called network-interface: define network-interface ( $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask = '''') { file { "ifcfg-$name": path => "/etc/sysconfig/network-scripts/ifcfg-$name", owner => "root", group => "root", mode => 0444, content => template("network-interface/sysconfig-ifcfg.erb"), notify => Service[network], } } which uses the ERB template "network-interface/sysconfig-ifcfg.erb": DEVICE=<%= name %> HWADDR=<%= hwaddr %> ONBOOT=<%= onboot %> BOOTPROTO=<%= bootproto %><% if bootproto.eql?("static") %> IPADDR=<%= ipaddr %> NETMASK=<%= netmask %><% elsif bootproto.eql?("dhcp") %> PEERDNS=no DHCPCLASS=<% end %> I provide the appropriate MAC addresses for a node by specifying them in the node file: node somehost inherits xenserver { network-interface { eth0: onboot => "yes", bootproto => "static", ipaddr => "123.45.67.89", hwaddr => "00:00:00:ab:cd:ef", netmask => "255.255.255.0", } network-interface { eth1: onboot => "yes", bootproto => "dhcp", hwaddr => "00:00:00:ab:cd:f0", } } Unfortunately, there''s a problem with this method. On Red Hat systems, you should stop networking before you change the HWADDR values in ifcfg-eth* files. If you don''t stop networking beforehand, Red Hat''s ifdown script chokes, and Puppet will just sit there, trying and trying to restart Service["network"]. Of course, a reboot will fix the problem, as will a manual restart of the network service. Here''s what would be nice: a metaparameter that tells Puppet to perform some action before modifying a resource. Here''s an example network-interface definition that has the non-existent feature I''m describing (a "preaction" metaparameter): define network-interface ( $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask = '''') { file { "ifcfg-$name": path => "/etc/sysconfig/network-scripts/ifcfg-$name", owner => "root", group => "root", mode => 0444, content => template("network-interface/sysconfig-ifcfg.erb"), notify => Service[network], preaction => "/sbin/ifdown $name", } } So this metaparameter would behave like this: 1. If the file resource "/etc/sysconfig/network-scripts/ifcfg- $name" is about to be changed, perform the preaction associated with that file resource. 2. Make the change to the file resource "/etc/sysconfig/network- scripts/ifcfg-$name". 3. Then, as usual, the resource notifies any other resources (Service["network"] in this example), if configured to do so. I used a shell command in my example above, but I''m sure there is a more elegant way to design this into the Puppet language, since going out to the shell is frowned upon. But however it''s implemented, the idea is the same. There should be some way to specify that an action must take place: 1. before the modification of a specifying resource, and 2. if and only if the specifying resource will actually be modified Karl Ward karl.ward at hunter.cuny.edu Hunter College ICIT Network Services -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.madstop.com/pipermail/puppet-users/attachments/20070823/4416f124/attachment.htm
Uhm, I got the require''s wrong in my example, and you might need to use another level of indirection, but I think you should be able to cobble something together. Thijs On 23/08/07, Thijs Oppermann <thijso+puppet at gmail.com> wrote:> > On 23/08/07, Karl Ward <karl.ward at hunter.cuny.edu> wrote: > > > I''ve been using Puppet now for a month or so and I''ve come to a problem > > that may warrant an additional Puppet metaparameter. I''m advocating the > > addition of a metaparameter called "preaction" (or something like that), > > which will perform some arbitrary action before the resource is modified. > > There may be a way to do this within Puppet already (with some carefully > > crafted dependencies, auxiliary files, and an exec resource with an onlyif > > parameter). In the end, this feels like a complicated workaround, and seems > > to me that before/require/subscribe/notify won''t cut it. > > > > The problem: With some PC hardware, the Linux kernel''s enumeration of > > ethernet device instances doesn''t match the hardware''s understanding of > > which ethernet card is first. For example, using Fedora 6 on a Dell 1950, > > eth0 corresponds to the onboard ethernet port labeled "2", and eth1 > > corresponds to the onboard ethernet port labeled "1". This is described in > > detail at > > http://linux.dell.com/files/whitepapers/nic-enum-whitepaper-v3.pdf . > > Luckily, this is fixable using Red Hat''s HWADDR sysconfig hack, and I > > implement this HWADDR fix with Puppet. Puppet writes > > /etc/sysconfig/network/ifcfg-eth0 and /etc/sysconfig/network/ifcfg-eth1 > > using a Puppet definition called network-interface: > > > > define network-interface ( > > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask > > '''') { > > file { "ifcfg-$name": > > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > > owner => "root", > > group => "root", > > mode => 0444, > > content => template("network-interface/sysconfig-ifcfg.erb"), > > notify => Service[network], > > } > > } > > > > which uses the ERB template "network-interface/sysconfig-ifcfg.erb": > > > > DEVICE=<%= name %> > > HWADDR=<%= hwaddr %> > > ONBOOT=<%= onboot %> > > BOOTPROTO=<%= bootproto %><% if bootproto.eql?("static") %> > > IPADDR=<%= ipaddr %> > > NETMASK=<%= netmask %><% elsif bootproto.eql ?("dhcp") %> > > PEERDNS=no > > DHCPCLASS=<% end %> > > > > I provide the appropriate MAC addresses for a node by specifying them in > > the node file: > > > > node somehost inherits xenserver { > > network-interface { eth0: > > onboot => "yes", > > bootproto => "static", > > ipaddr => " 123.45.67.89", > > hwaddr => "00:00:00:ab:cd:ef", > > netmask => "255.255.255.0 ", > > } > > network-interface { eth1: > > onboot => "yes", > > bootproto => "dhcp", > > hwaddr => "00:00:00:ab:cd:f0", > > } > > } > > > > Unfortunately, there''s a problem with this method. On Red Hat systems, > > you should stop networking before you change the HWADDR values in ifcfg-eth* > > files. If you don''t stop networking beforehand, Red Hat''s ifdown script > > chokes, and Puppet will just sit there, trying and trying to restart > > Service["network"]. Of course, a reboot will fix the problem, as will a > > manual restart of the network service. Here''s what would be nice: a > > metaparameter that tells Puppet to perform some action before modifying a > > resource. Here''s an example network-interface definition that has the > > non-existent feature I''m describing (a "preaction" metaparameter): > > > > define network-interface ( > > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask > > '''') { > > file { "ifcfg-$name": > > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > > owner => "root", > > group => "root", > > mode => 0444, > > content => template("network-interface/sysconfig-ifcfg.erb"), > > notify => Service[network], > > preaction => "/sbin/ifdown $name", > > } > > } > > > > So this metaparameter would behave like this: > > > > 1. If the file resource "/etc/sysconfig/network-scripts/ifcfg-$name" is > > about to be changed, perform the preaction associated with that file > > resource. > > 2. Make the change to the file resource > > "/etc/sysconfig/network-scripts/ifcfg-$name". > > 3. Then, as usual, the resource notifies any other resources > > (Service["network"] in this example), if configured to do so. > > > > I used a shell command in my example above, but I''m sure there is a more > > elegant way to design this into the Puppet language, since going out to the > > shell is frowned upon. But however it''s implemented, the idea is the same. > > There should be some way to specify that an action must take place: > > > > 1. before the modification of a specifying resource, and > > 2. if and only if the specifying resource will actually be modified > > > > I think you should already be able to get this behaviour using exec, > notify and refreshonly. Something like: > > define network-interface ( > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask > '''') { > file { "ifcfg-$name": > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > owner => "root", > group => "root", > mode => 0444, > content => template("network-interface/sysconfig-ifcfg.erb "), > notify => [ Service[network], Exec[ifdown] ], > } } > > exec { "ifdown": > command => "/sbin/ifdown $name", > refreshonly => true, > require => File["ifcfg-$name"], > } > > Not tested of course, but you get the idea. > > Thijs > > Karl Ward > > karl.ward at hunter.cuny.edu > > Hunter College ICIT Network Services > > > > > > > > _______________________________________________ > > Puppet-users mailing list > > Puppet-users at madstop.com > > https://mail.madstop.com/mailman/listinfo/puppet-users > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.madstop.com/pipermail/puppet-users/attachments/20070823/d45179d1/attachment-0001.htm
On 23/08/07, Karl Ward <karl.ward@hunter.cuny.edu> wrote:> > I''ve been using Puppet now for a month or so and I''ve come to a problem > that may warrant an additional Puppet metaparameter. I''m advocating the > addition of a metaparameter called "preaction" (or something like that), > which will perform some arbitrary action before the resource is modified. > There may be a way to do this within Puppet already (with some carefully > crafted dependencies, auxiliary files, and an exec resource with an onlyif > parameter). In the end, this feels like a complicated workaround, and seems > to me that before/require/subscribe/notify won''t cut it. > > The problem: With some PC hardware, the Linux kernel''s enumeration of > ethernet device instances doesn''t match the hardware''s understanding of > which ethernet card is first. For example, using Fedora 6 on a Dell 1950, > eth0 corresponds to the onboard ethernet port labeled "2", and eth1 > corresponds to the onboard ethernet port labeled "1". This is described in > detail at > http://linux.dell.com/files/whitepapers/nic-enum-whitepaper-v3.pdf . > Luckily, this is fixable using Red Hat''s HWADDR sysconfig hack, and I > implement this HWADDR fix with Puppet. Puppet writes > /etc/sysconfig/network/ifcfg-eth0 and /etc/sysconfig/network/ifcfg-eth1 > using a Puppet definition called network-interface: > > define network-interface ( > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask > '''') { > file { "ifcfg-$name": > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > owner => "root", > group => "root", > mode => 0444, > content => template("network-interface/sysconfig-ifcfg.erb"), > notify => Service[network], > } > } > > which uses the ERB template "network-interface/sysconfig-ifcfg.erb": > > DEVICE=<%= name %> > HWADDR=<%= hwaddr %> > ONBOOT=<%= onboot %> > BOOTPROTO=<%= bootproto %><% if bootproto.eql?("static") %> > IPADDR=<%= ipaddr %> > NETMASK=<%= netmask %><% elsif bootproto.eql?("dhcp") %> > PEERDNS=no > DHCPCLASS=<% end %> > > I provide the appropriate MAC addresses for a node by specifying them in > the node file: > > node somehost inherits xenserver { > network-interface { eth0: > onboot => "yes", > bootproto => "static", > ipaddr => "123.45.67.89", > hwaddr => "00:00:00:ab:cd:ef", > netmask => "255.255.255.0", > } > network-interface { eth1: > onboot => "yes", > bootproto => "dhcp", > hwaddr => "00:00:00:ab:cd:f0", > } > } > > Unfortunately, there''s a problem with this method. On Red Hat systems, > you should stop networking before you change the HWADDR values in ifcfg-eth* > files. If you don''t stop networking beforehand, Red Hat''s ifdown script > chokes, and Puppet will just sit there, trying and trying to restart > Service["network"]. Of course, a reboot will fix the problem, as will a > manual restart of the network service. Here''s what would be nice: a > metaparameter that tells Puppet to perform some action before modifying a > resource. Here''s an example network-interface definition that has the > non-existent feature I''m describing (a "preaction" metaparameter): > > define network-interface ( > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask > '''') { > file { "ifcfg-$name": > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > owner => "root", > group => "root", > mode => 0444, > content => template("network-interface/sysconfig-ifcfg.erb"), > notify => Service[network], > preaction => "/sbin/ifdown $name", > } > } > > So this metaparameter would behave like this: > > 1. If the file resource "/etc/sysconfig/network-scripts/ifcfg-$name" is > about to be changed, perform the preaction associated with that file > resource. > 2. Make the change to the file resource > "/etc/sysconfig/network-scripts/ifcfg-$name". > 3. Then, as usual, the resource notifies any other resources > (Service["network"] in this example), if configured to do so. > > I used a shell command in my example above, but I''m sure there is a more > elegant way to design this into the Puppet language, since going out to the > shell is frowned upon. But however it''s implemented, the idea is the same. > There should be some way to specify that an action must take place: > > 1. before the modification of a specifying resource, and > 2. if and only if the specifying resource will actually be modified >I think you should already be able to get this behaviour using exec, notify and refreshonly. Something like: define network-interface ( $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, $netmask = '''') { file { "ifcfg-$name": path => "/etc/sysconfig/network-scripts/ifcfg-$name", owner => "root", group => "root", mode => 0444, content => template("network-interface/sysconfig-ifcfg.erb"), notify => [ Service[network], Exec[ifdown] ], } } exec { "ifdown": command => "/sbin/ifdown $name", refreshonly => true, require => File["ifcfg-$name"], } Not tested of course, but you get the idea. Thijs Karl Ward> karl.ward@hunter.cuny.edu > Hunter College ICIT Network Services > > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users > >_______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Just replace "$name" everywhere with an additional param "$eth_number" or something, use "subscribe => File["ifcfg-$eth_number"]" instead of "require" in the exec and you should be fine. Maybe not as beautyfull as the use of $name because you´ll most likely do "network-interface {"eth0": eth_number => eth0, [...]}" but it should work (not tested but i´ve had quite a similar case a few days ago, so if memory serves right.. I´ll check tomorrow at work). hth Thijs Oppermann schrieb:> Uhm, I got the require''s wrong in my example, and you might need to > use another level of indirection, but I think you should be able to > cobble something together. > > Thijs > > On 23/08/07, * Thijs Oppermann* <thijso+puppet@gmail.com > <mailto:thijso+puppet@gmail.com>> wrote: > > On 23/08/07, *Karl Ward* <karl.ward@hunter.cuny.edu > <mailto:karl.ward@hunter.cuny.edu>> wrote: > > I''ve been using Puppet now for a month or so and I''ve come to > a problem that may warrant an additional Puppet > metaparameter. I''m advocating the addition of a metaparameter > called "preaction" (or something like that), which will > perform some arbitrary action before the resource is > modified. There may be a way to do this within Puppet already > (with some carefully crafted dependencies, auxiliary files, > and an exec resource with an onlyif parameter). In the end, > this feels like a complicated workaround, and seems to me that > before/require/subscribe/notify won''t cut it. > > The problem: With some PC hardware, the Linux kernel''s > enumeration of ethernet device instances doesn''t match the > hardware''s understanding of which ethernet card is first. For > example, using Fedora 6 on a Dell 1950, eth0 corresponds to > the onboard ethernet port labeled "2", and eth1 corresponds to > the onboard ethernet port labeled "1". This is described in > detail at > http://linux.dell.com/files/whitepapers/nic-enum-whitepaper-v3.pdf > . Luckily, this is fixable using Red Hat''s HWADDR sysconfig > hack, and I implement this HWADDR fix with Puppet. Puppet > writes /etc/sysconfig/network/ifcfg-eth0 and > /etc/sysconfig/network/ifcfg-eth1 using a Puppet definition > called network-interface: > > define network-interface ( > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, > $netmask = '''') { > file { "ifcfg-$name": > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > > > owner => "root", > group => "root", > mode => 0444, > > > content => template("network-interface/sysconfig-ifcfg.erb"), > notify => Service[network], > } > } > > which uses the ERB template > "network-interface/sysconfig-ifcfg.erb": > > DEVICE=<%= name %> > HWADDR=<%= hwaddr %> > ONBOOT=<%= onboot %> > BOOTPROTO=<%= bootproto %><% if bootproto.eql?("static") %> > IPADDR=<%= ipaddr %> > NETMASK=<%= netmask %><% elsif bootproto.eql ?("dhcp") %> > PEERDNS=no > DHCPCLASS=<% end %> > > I provide the appropriate MAC addresses for a node by > specifying them in the node file: > > node somehost inherits xenserver { > network-interface { eth0: > > > onboot => "yes", > bootproto => "static", > ipaddr => " 123.45.67.89 <http://123.45.67.89>", > hwaddr => "00:00:00:ab:cd:ef", > > netmask => "255.255.255.0 <http://255.255.255.0>", > } > network-interface { eth1: > onboot => "yes", > bootproto => "dhcp", > hwaddr => "00:00:00:ab:cd:f0", > > > } > } > > Unfortunately, there''s a problem with this method. On Red Hat > systems, you should stop networking before you change the > HWADDR values in ifcfg-eth* files. If you don''t stop > networking beforehand, Red Hat''s ifdown script chokes, and > Puppet will just sit there, trying and trying to restart > Service["network"]. Of course, a reboot will fix the problem, > as will a manual restart of the network service. Here''s what > would be nice: a metaparameter that tells Puppet to perform > some action before modifying a resource. Here''s an example > network-interface definition that has the non-existent feature > I''m describing (a "preaction" metaparameter): > > define network-interface ( > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, > $netmask = '''') { > file { "ifcfg-$name": > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > > > owner => "root", > group => "root", > mode => 0444, > > > content => template("network-interface/sysconfig-ifcfg.erb"), > notify => Service[network], > preaction => "/sbin/ifdown $name", > } > } > > So this metaparameter would behave like this: > > > > 1. If the file resource > "/etc/sysconfig/network-scripts/ifcfg-$name" is about to be > changed, perform the preaction associated with that file > resource. > 2. Make the change to the file resource > "/etc/sysconfig/network-scripts/ifcfg-$name". > 3. Then, as usual, the resource notifies any other resources > (Service["network"] in this example), if configured to do so. > > I used a shell command in my example above, but I''m sure there > is a more elegant way to design this into the Puppet language, > since going out to the shell is frowned upon. But however > it''s implemented, the idea is the same. There should be some > way to specify that an action must take place: > > 1. before the modification of a specifying resource, and > 2. if and only if the specifying resource will actually be > modified > > > I think you should already be able to get this behaviour using > exec, notify and refreshonly. Something like: > > define network-interface ( > $onboot = ''no'', $bootproto = ''static'', $ipaddr = '''', $hwaddr, > $netmask = '''') { > file { "ifcfg-$name": > path => "/etc/sysconfig/network-scripts/ifcfg-$name", > owner => "root", > > > group => "root", > mode => 0444, > content => template("network-interface/sysconfig- ifcfg.erb "), > notify => [ Service[network], Exec[ifdown] ], > } > > > } > > exec { "ifdown": > command => "/sbin/ifdown $name", > > > refreshonly => true, > > > require => File["ifcfg-$name"], > } > > Not tested of course, but you get the idea. > > Thijs > > Karl Ward > karl.ward@hunter.cuny.edu <mailto:karl.ward@hunter.cuny.edu> > Hunter College ICIT Network Services > > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com <mailto:Puppet-users@madstop.com> > https://mail.madstop.com/mailman/listinfo/puppet-users > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >