Daniel Pittman
2009-Dec-22 13:00 UTC
[Puppet Users] using ''define'': modelling a file-like construction.
G''day.
I sometimes want to write a ''define'' that wraps some higher
level behaviour
around a low level ''file'' statement, akin to this:
define example ($source = false, $content = false) {
file { "/path/to/whatever/${name}":
ensure => file, source => $source, content => $content,
notify => Service["some-service"],
etc, etc, etc
}
}
This is great, except it doesn''t work. It returns an error that source
is
nil, if I specify content, and that is that.
Instead, I get to write out the same file stanza twice, once with content and
once with source, as well as a third stanza that fails when neither is set.
Wouldn''t it be wonderful if there was a standard way to express this
idiom?
Daniel
...now someone is gonna tell me that I missed something obvious, but that is
fine with me: saving the time I waste on these is worth enough for me. :)
--
✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
--
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.
R.I.Pienaar
2009-Dec-22 13:14 UTC
Re: [Puppet Users] using ''define'': modelling a file-like construction.
hello,
You can use the ability to set defaults for resources:
define mfile($content = undef, $source = undef) {
if $content {
File[$name] {
content => $content
}
} else {
File[$name] {
source => $source
}
}
file{$name: }
}
----- "Daniel Pittman" <daniel@rimspace.net> wrote:
> G''day.
>
> I sometimes want to write a ''define'' that wraps some
higher level
> behaviour
> around a low level ''file'' statement, akin to this:
>
> define example ($source = false, $content = false) {
> file { "/path/to/whatever/${name}":
> ensure => file, source => $source, content => $content,
> notify => Service["some-service"],
> etc, etc, etc
> }
> }
>
> This is great, except it doesn''t work. It returns an error that
> source is
> nil, if I specify content, and that is that.
>
> Instead, I get to write out the same file stanza twice, once with
> content and
> once with source, as well as a third stanza that fails when neither is
> set.
>
>
> Wouldn''t it be wonderful if there was a standard way to express
this
> idiom?
>
> Daniel
>
> ...now someone is gonna tell me that I missed something obvious, but
> that is
> fine with me: saving the time I waste on these is worth enough for me.
> :)
>
> --
> ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401
> 155 707
> ♽ made with 100 percent post-consumer electrons
>
> --
>
> 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.
--
R.I.Pienaar
--
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.
Trevor Vaughan
2009-Dec-23 01:49 UTC
Re: [Puppet Users] using ''define'': modelling a file-like construction.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I''m not sure if this will work as I haven''t tested it, but try setting source and content to ''undef'' (no quotes) instead of false. Trevor On 12/22/2009 08:00 AM, Daniel Pittman wrote:> G''day. > > I sometimes want to write a ''define'' that wraps some higher level behaviour > around a low level ''file'' statement, akin to this: > > define example ($source = false, $content = false) { > file { "/path/to/whatever/${name}": > ensure => file, source => $source, content => $content, > notify => Service["some-service"], > etc, etc, etc > } > } > > This is great, except it doesn''t work. It returns an error that source is > nil, if I specify content, and that is that. > > Instead, I get to write out the same file stanza twice, once with content and > once with source, as well as a third stanza that fails when neither is set. > > > Wouldn''t it be wonderful if there was a standard way to express this idiom? > > Daniel > > ...now someone is gonna tell me that I missed something obvious, but that is > fine with me: saving the time I waste on these is worth enough for me. :) >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAksxdz8ACgkQyjMdFR1108DeswCeMoBu3E3/LeXuGzXqn9rUzVAF u9AAoKwvA7MxlfhNAl9PD6pnFrQSB176 =q/Dw -----END PGP SIGNATURE----- -- 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.
Trevor Vaughan
2009-Dec-24 10:32 UTC
Re: [Puppet Users] using ''define'': modelling a file-like construction.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Wouldn''t this possibly have unintended consequences, or would the scope of the overrides be restricted to the define in this case? Trevor On 12/22/2009 08:14 AM, R.I.Pienaar wrote:> hello, > > You can use the ability to set defaults for resources: > > define mfile($content = undef, $source = undef) { > if $content { > File[$name] { > content => $content > } > } else { > File[$name] { > source => $source > } > } > > file{$name: } > } > > > > ----- "Daniel Pittman" <daniel@rimspace.net> wrote: > >> G''day. >> >> I sometimes want to write a ''define'' that wraps some higher level >> behaviour >> around a low level ''file'' statement, akin to this: >> >> define example ($source = false, $content = false) { >> file { "/path/to/whatever/${name}": >> ensure => file, source => $source, content => $content, >> notify => Service["some-service"], >> etc, etc, etc >> } >> } >> >> This is great, except it doesn''t work. It returns an error that >> source is >> nil, if I specify content, and that is that. >> >> Instead, I get to write out the same file stanza twice, once with >> content and >> once with source, as well as a third stanza that fails when neither is >> set. >> >> >> Wouldn''t it be wonderful if there was a standard way to express this >> idiom? >> >> Daniel >> >> ...now someone is gonna tell me that I missed something obvious, but >> that is >> fine with me: saving the time I waste on these is worth enough for me. >> :) >> >> -- >> ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 >> 155 707 >> ♽ made with 100 percent post-consumer electrons >> >> -- >> >> 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. >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkszQy0ACgkQyjMdFR1108B18gCdFlXjDTAkiM7+6itiTS5DXab6 gAYAoKaRhcCPk9v0lc1ZxLb4hcNcUXNo =t2F3 -----END PGP SIGNATURE----- -- 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.
Peter Meier
2009-Dec-24 12:17 UTC
Re: [Puppet Users] using ''define'': modelling a file-like construction.
> Wouldn''t this possibly have unintended consequences, or would the scope > of the overrides be restricted to the define in this case?afair it''s restricted to the scope. cheers pete -- 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.