I''m trying to write a wrapper definition for the file type to make it a bit smarter. I have a basic version working fairly well: define xfile($owner = root, $group = root, $mode = 644, $source, $backup = main, $recurse = false, $ensure = file) { file { $name: mode => $mode, owner => $owner, group => $group, backup => $backup, recurse => $recurse, ensure => $ensure, source => [ "puppet://$server/dist/$source.$host", "puppet://$server/dist/$source.$operatingsystem", "puppet://$server/dist/$source" } } The big hitch now is that FreeBSD, of course, doesn''t do the "root" group. It wants "wheel". So I figure what I want to do is take a look at $group and $operatingsystem, and if need be translate "root" to "wheel". I really don''t want to be specifying the group on every file. The docco is somewhat lacking in describing syntax for boolean expressions for "if" statements, so I''ve been trying to figure out how to express that. None of the obvious things I can think of work. Hint? Matt
>>>>> "Matt" == McLeod, Matt <Matt.McLeod@itg.com> writes:Matt> The big hitch now is that FreeBSD, of course, doesn''t do the Matt> "root" group. It wants "wheel". So I figure what I want to Matt> do is take a look at $group and $operatingsystem, and if Matt> need be translate "root" to "wheel". I really don''t want to Matt> be specifying the group on every file. I think (me newbie) you want the following , http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#selectors :- group => $os ? { freebsd => "wheel", default => "root", } Sincerely, Adrian Phillips -- Who really wrote the works of William Shakespeare ? http://www.pbs.org/wgbh/pages/frontline/shakespeare/
The complication (and apologies for the lousy Outlook-style quoting) is that if $group was set to anything other than "root" then it should be left alone. I''ve tried the obvious stuff like: if $group = "root" and $operatingsystem = "freebsd" {} (with variations of "==" and "&&", because even that doesn''t appear to be documented, the only example in the docco is of the "if $var {}" form). I''ve also tried: if $group = "root" { $group = $operatingsystem ? { "freebsd" => "wheel", "default" => "root" } } But that''s failing on the initial if too so clearly I need to figure that bit out first. Had trouble with something similar last week and cheated by using "case" instead, but I''d rather just get this right. Matt -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Adrian Phillips Sent: Monday, 29 October 2007 4:55 PM To: Puppet User Discussion Subject: Re: [Puppet-users] Boolean expressions>>>>> "Matt" == McLeod, Matt <Matt.McLeod@itg.com> writes:Matt> The big hitch now is that FreeBSD, of course, doesn''t do the Matt> "root" group. It wants "wheel". So I figure what I want to Matt> do is take a look at $group and $operatingsystem, and if Matt> need be translate "root" to "wheel". I really don''t want to Matt> be specifying the group on every file. I think (me newbie) you want the following , http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#selectors :- group => $os ? { freebsd => "wheel", default => "root", } Sincerely, Adrian Phillips -- Who really wrote the works of William Shakespeare ? http://www.pbs.org/wgbh/pages/frontline/shakespeare/ _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
> The docco is somewhat lacking in describing syntax for boolean > expressions for "if" statements, so I''ve been trying to figure out how > to express that. None of the obvious things I can think of work. Hint?The documentation doesn''t describe the syntax because the only syntax that is currently supported is existence i.e., if $variable { file { "/some/file": ensure => present } } else { file { "/some/other/file": ensure => present } } A construct like: if $variable = "value" { do... } else { do... } is not yet supported. Regards James Turnbull -- James Turnbull <james@lovedthanlost.net> --- Author of Pro Nagios 2.0 (http://www.amazon.com/gp/product/1590596099/) Hardening Linux (http://www.amazon.com/gp/product/1590594444/) --- PGP Key (http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x0C42DF40) _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Thanks. That seems pretty stupid, but at least now I can quit banging my head against this particular wall and go cross-eyed with case statements instead. Matt -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of James Turnbull Sent: Monday, 29 October 2007 5:26 PM To: Puppet User Discussion Subject: Re: [Puppet-users] Boolean expressions> The docco is somewhat lacking in describing syntax for boolean > expressions for "if" statements, so I''ve been trying to figure out how > to express that. None of the obvious things I can think of work.Hint? The documentation doesn''t describe the syntax because the only syntax that is currently supported is existence i.e., if $variable { file { "/some/file": ensure => present } } else { file { "/some/other/file": ensure => present } } A construct like: if $variable = "value" { do... } else { do... } is not yet supported. Regards James Turnbull -- James Turnbull <james@lovedthanlost.net> --- Author of Pro Nagios 2.0 (http://www.amazon.com/gp/product/1590596099/) Hardening Linux (http://www.amazon.com/gp/product/1590594444/) --- PGP Key (http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x0C42DF40)
McLeod, Matt wrote:> Thanks. That seems pretty stupid, but at least now I can quit banging > my head against this particular wall and go cross-eyed with case > statements instead. >I agree it''s very limited. If this is something you''re after I recommend logging a ticket with a feature request. Regards James Turnbull -- James Turnbull <james@lovedthanlost.net> --- Author of Pro Nagios 2.0 (http://www.amazon.com/gp/product/1590596099/) Hardening Linux (http://www.amazon.com/gp/product/1590594444/) --- PGP Key (http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x0C42DF40) _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 29 October 2007, McLeod, Matt wrote:> The complication (and apologies for the lousy Outlook-style quoting) is > that if $group was set to anything other than "root" then it should be > left alone. > > I''ve tried the obvious stuff like: > > if $group = "root" and $operatingsystem = "freebsd" {} > > (with variations of "==" and "&&", because even that doesn''t appear to > be documented, the only example in the docco is of the "if $var {}" > form). > > I''ve also tried: > > if $group = "root" { > $group = $operatingsystem ? { > "freebsd" => "wheel", > "default" => "root" > } > } > > But that''s failing on the initial if too so clearly I need to figure > that bit out first. > > Had trouble with something similar last week and cheated by using "case" > instead, but I''d rather just get this right.Assuming ''root'' on FreeBSD always means wheel: group => $operatingsystem ? { ''freebsd'' => $group ? { ''root'' => ''wheel'', # remove this, if the user knows better '''' => ''wheel'', default => $group }, default => $group ? { '''' => ''root'', default => ''root'' } } Regards, David - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHJZGl/Pp1N6Uzh0URAsHUAJ49L7mfLOVQvbUABC86Ht5DR1VRvgCfQbi2 P0mJ6XI0rWvHo1WaYE+YFTM=eh2K -----END PGP SIGNATURE-----
for the root group, use a custom fact like this: Facter.add("rootgroup") do require ''etc'' setcode { Etc.getgrgid(0).name.strip } end now $rootgroup is the good one whatever platform you are in :) -- Cordialement, Ghislain _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
On Mon, Oct 29, 2007 at 04:50:50PM +1100, McLeod, Matt wrote:> I''m trying to write a wrapper definition for the file type to make it a > bit smarter. I have a basic version working fairly well: > > define xfile($owner = root, $group = root, $mode = 644, $source,[...] This is also the route we have taken, unfortunately. From bitter experience, I now advise against it, at least until http://reductivelabs.com/trac/puppet/ticket/446 is fixed. Otherwise, you will find that dependancies involving xfiles are sometimes mysteriously ignored. To make your life a bit easier, consider defining defaults using: File { owner => root, ... } at the top level. -- Marcin Owsiany Web Systems Integrator - Guardian Unlimited ------------------------------------------------------------------ Visit Guardian Unlimited - the UK''s most popular newspaper website http://guardian.co.uk http://observer.co.uk ------------------------------------------------------------------ The Newspaper Marketing Agency Opening Up Newspapers http://www.nmauk.co.uk ------------------------------------------------------------------ This e-mail and all attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender and delete the e-mail and all attachments immediately. Do not disclose the contents to another person. You may not use the information for any purpose, or store, or copy, it in any way. Guardian News & Media Limited is not liable for any computer viruses or other material transmitted with or as part of this e-mail. You should employ virus checking software. Guardian News & Media Limited A member of Guardian Media Group PLC Registered Office Number 1 Scott Place, Manchester M3 3GG Registered in England Number 908396
McLeod, Matt wrote:> The big hitch now is that FreeBSD, of course, doesn''t do the "root" > group. It wants "wheel".Why not specify the group numerically?
On Oct 29, 2007, at 1:15 AM, McLeod, Matt wrote:> if $group = "root" { > $group = $operatingsystem ? { > "freebsd" => "wheel", > "default" => "root" > } > }I''ve always solved this with default values, overrides, and selectors, at least in definitions: define myfile(..., $group = false) { file { "...": ... } # no group setting if $group { File[$name] { group => $operatingsystem ? { ... } } } } It''s not pretty, and it can get especially hairy as you get lots of default values, but at least you only have to write it once. In general, for this problem I recommend either sticking with numerical group information or setting a top-level ''$rootgroup'' variable using this selector, so that everyone else can use group => $rootgroup, instead of having the selector duplicated 50 times in your configuration. -- This space intentionally has nothing but text explaining why this space has nothing but text explaining that this space would otherwise have been left blank, and would otherwise have been left blank. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Defaults aren''t really what I''m trying to solve. The goal is to not have to specify the selector stuff every time I specify a file. Not using "require" at present but our machines are pretty homogenous. Matt -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Marcin Owsiany Sent: Monday, 29 October 2007 7:19 PM To: puppet-users@madstop.com Subject: Re: [Puppet-users] Boolean expressions On Mon, Oct 29, 2007 at 04:50:50PM +1100, McLeod, Matt wrote:> I''m trying to write a wrapper definition for the file type to make ita> bit smarter. I have a basic version working fairly well: > > define xfile($owner = root, $group = root, $mode = 644, $source,[...] This is also the route we have taken, unfortunately. From bitter experience, I now advise against it, at least until http://reductivelabs.com/trac/puppet/ticket/446 is fixed. Otherwise, you will find that dependancies involving xfiles are sometimes mysteriously ignored. To make your life a bit easier, consider defining defaults using: File { owner => root, ... } at the top level. -- Marcin Owsiany Web Systems Integrator - Guardian Unlimited ------------------------------------------------------------------ Visit Guardian Unlimited - the UK''s most popular newspaper website http://guardian.co.uk http://observer.co.uk ------------------------------------------------------------------ The Newspaper Marketing Agency Opening Up Newspapers http://www.nmauk.co.uk ------------------------------------------------------------------ This e-mail and all attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender and delete the e-mail and all attachments immediately. Do not disclose the contents to another person. You may not use the information for any purpose, or store, or copy, it in any way. Guardian News & Media Limited is not liable for any computer viruses or other material transmitted with or as part of this e-mail. You should employ virus checking software. Guardian News & Media Limited A member of Guardian Media Group PLC Registered Office Number 1 Scott Place, Manchester M3 3GG Registered in England Number 908396 _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Good point. Really should have thought of that. -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Brendan Strejcek Sent: Tuesday, 30 October 2007 12:17 AM To: Puppet User Discussion Subject: Re: [Puppet-users] Boolean expressions McLeod, Matt wrote:> The big hitch now is that FreeBSD, of course, doesn''t do the "root" > group. It wants "wheel".Why not specify the group numerically? _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users