What is the right way to write definition so that defaults can be overriden? $puppetdir = "puppet://$server/files" define remotefile($source, $owner = "root", $group = "root", $mode 0644, $backup = false, $recurse = false) { file { $name: mode => $mode, owner => $owner, group => $group, backup => $backup, recurse => $recurse, source => "$puppetdir/$source", } } I discovered that this does not allow overriding $puppetdir. define remotefile($source, $owner = "root", $group = "root", $mode 0644, $backup = false, $recurse = false, $puppetdir = $puppetdir) { Remotefile { puppetdir => "file:///home/imb/puppet/files" } Is there a better way to do this? - Ian
On Mar 7, 2007, at 5:27 PM, Ian Burrell wrote:> What is the right way to write definition so that defaults can be > overriden? > > $puppetdir = "puppet://$server/files" > > define remotefile($source, $owner = "root", $group = "root", $mode > 0644, $backup = false, $recurse = false) { > file { $name: > mode => $mode, > owner => $owner, > group => $group, > backup => $backup, > recurse => $recurse, > source => "$puppetdir/$source", > } > } > > I discovered that this does not allow overriding $puppetdir. > > define remotefile($source, $owner = "root", $group = "root", $mode > 0644, $backup = false, $recurse = false, $puppetdir = $puppetdir) { > > Remotefile { puppetdir => "file:///home/imb/puppet/files" } > > Is there a better way to do this?Why do you even want the $puppetdir defined at all? Why not just specify it as a normal parameter with a default value in your definition of ''remotefile''? Otherwise, though, you''re right that this is not easily done with Puppet ATM. -- Good judgment comes from experience, and experience comes from bad judgment. --Barry LePatner --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On 3/9/07, Luke Kanies <luke@madstop.com> wrote:> On Mar 7, 2007, at 5:27 PM, Ian Burrell wrote: > > define remotefile($source, $owner = "root", $group = "root", $mode > > 0644, $backup = false, $recurse = false, $puppetdir = $puppetdir) { > > > > Remotefile { puppetdir => "file:///home/imb/puppet/files" } > > > > Is there a better way to do this? > > Why do you even want the $puppetdir defined at all? Why not just > specify it as a normal parameter with a default value in your > definition of > ''remotefile''? >I just like having the constant be declared at the top as a separate variable. Naming it the same as the parameter is confusing. Is the puppet server defined as a variable? - Ian
David Lutterkort
2007-Mar-14 23:54 UTC
Re: Writing definitions to support changing defaults
On Wed, 2007-03-14 at 14:01 -0700, Ian Burrell wrote:> On 3/9/07, Luke Kanies <luke@madstop.com> wrote: > > On Mar 7, 2007, at 5:27 PM, Ian Burrell wrote: > > > define remotefile($source, $owner = "root", $group = "root", $mode > > > 0644, $backup = false, $recurse = false, $puppetdir = $puppetdir) { > > > > > > Remotefile { puppetdir => "file:///home/imb/puppet/files" } > > > > > > Is there a better way to do this? > > > > Why do you even want the $puppetdir defined at all? Why not just > > specify it as a normal parameter with a default value in your > > definition of > > ''remotefile''? > > > > I just like having the constant be declared at the top as a separate > variable. Naming it the same as the parameter is confusing. > > Is the puppet server defined as a variable?It''s $server AFAIK, i.e. a source of "puppet://$server/foo/bar.txt" should do the right thing in most cases. David
On 3/14/07, David Lutterkort <dlutter@redhat.com> wrote:> On Wed, 2007-03-14 at 14:01 -0700, Ian Burrell wrote: > > > > Is the puppet server defined as a variable? > > It''s $server AFAIK, i.e. a source of "puppet://$server/foo/bar.txt" > should do the right thing in most cases. >That doesn''t seem to work. I am getting bunches of "Could not connect to localhost on port 8140" errors from the remotefile resources. Their source is under "puppet://$server/files". - Ian
On Mar 15, 2007, at 10:54 AM, Ian Burrell wrote:> On 3/14/07, David Lutterkort <dlutter@redhat.com> wrote: >> On Wed, 2007-03-14 at 14:01 -0700, Ian Burrell wrote: >>> >>> Is the puppet server defined as a variable? >> >> It''s $server AFAIK, i.e. a source of "puppet://$server/foo/bar.txt" >> should do the right thing in most cases. >> > > That doesn''t seem to work. I am getting bunches of "Could not connect > to localhost on port 8140" errors from the remotefile resources. > Their source is under "puppet://$server/files".I don''t think Puppet sets that variable, or if it does, it''s in svn trunk and not yet released. -- Opportunity is missed by most people because it is dressed in overalls and looks like work. -- Thomas A. Edison --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On Mar 14, 2007, at 2:01 PM, Ian Burrell wrote:> I just like having the constant be declared at the top as a separate > variable. Naming it the same as the parameter is confusing.Ah. Yeah, there unfortunately isn''t really a good way to do this. I''d love to hear recommendations on how people would like this to work. -- A motion to adjourn is always in order. --Robert Heinlein --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
David Lutterkort
2007-Mar-15 18:21 UTC
Re: Writing definitions to support changing defaults
On Thu, 2007-03-15 at 10:54 -0700, Ian Burrell wrote:> On 3/14/07, David Lutterkort <dlutter@redhat.com> wrote: > > On Wed, 2007-03-14 at 14:01 -0700, Ian Burrell wrote: > > > > > > Is the puppet server defined as a variable? > > > > It''s $server AFAIK, i.e. a source of "puppet://$server/foo/bar.txt" > > should do the right thing in most cases. > > > > That doesn''t seem to work. I am getting bunches of "Could not connect > to localhost on port 8140" errors from the remotefile resources. > Their source is under "puppet://$server/files".Sorry, I should have checked my manifests first. I use ''$servername'', and that seems to work. David
On Mar 15, 2007, at 1:21 PM, David Lutterkort wrote:> > Sorry, I should have checked my manifests first. I use ''$servername'', > and that seems to work.Yeah, I checked into this, and I''ve been setting ''servername'' on the server, but it was not the fqdn. Note that 0.22.2 uses the server''s fqdn, no longer just the hostname. -- A diplomat is a man who can convince his wife she''d look stout in a fur coat. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com