Steve Wray
2009-Mar-09 23:59 UTC
[Puppet Users] More fun with conditionals and structure...
I want to stop ntpd on all domU and openvz virtual machines while enabling it on all dom0 and physical machines. I''ve been trying to get my head around this and searched through documentation and examples but cannot find anything like this so far. If its running Debian Sarge then the init script is /etc/init.d/ntp-server If its running Etch or Lenny then its /etc/init.d/ntp I''d thought that the "name" variable of ''service'' was supposed to indicate this? Or have I got my conditionals way wrong? Because the code I''ve included doesn''t seem to do anything at all. Not even a syntax error... class services { service { "ntp_service": name => $lsbdistcodename ? { ''sarge'' => "ntp-server", ''etch'' => "ntp", ''lenny'' => "ntp", }, case $virtual { ''xenu'',''openvz'': { ensure => stopped, enable => false, pattern => "ntpd" } ''xen0'',''physical'': { ensure => running, enable => true, pattern => "ntpd" } } } } -- Please remember that an email is just like a postcard; it is not confidential nor private nor secure and can be read by many other people than the intended recipient. A postcard can be read by anyone at the mail sorting office and expecting what is written on it to be private and secret is not realistic. Please hold no higher expectation of email. If you need to send confidential information in an email you need to use encryption. PGP is Pretty good for this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
RijilV
2009-Mar-10 00:27 UTC
[Puppet Users] Re: More fun with conditionals and structure...
2009/3/9 Steve Wray <steve.wray@cwa.co.nz>> > I want to stop ntpd on all domU and openvz virtual machines while enabling > it on all dom0 and physical machines. > > I''ve been trying to get my head around this and searched through > documentation and examples but cannot find anything like this so far. > > If its running Debian Sarge then the init script is /etc/init.d/ntp-server > > If its running Etch or Lenny then its /etc/init.d/ntp > > I''d thought that the "name" variable of ''service'' was supposed to indicate > this? Or have I got my conditionals way wrong? Because the code I''ve > included doesn''t seem to do anything at all. Not even a syntax error... > > > class services { > > service { "ntp_service": > > name => $lsbdistcodename ? { > ''sarge'' => "ntp-server", > ''etch'' => "ntp", > ''lenny'' => "ntp", > }, > > case $virtual { > ''xenu'',''openvz'': > { > ensure => stopped, > enable => false, > pattern => "ntpd" > } > ''xen0'',''physical'': > { > ensure => running, > enable => true, > pattern => "ntpd" > } > } > } > } >Kicks an error for me: $ puppet --parseonly test.pp err: Could not parse for environment production: Syntax error at ''case''; expected ''}'' at /raid/boaz/home/rijilv/test.pp:11 How are you testing your manifests? .r'' --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steve Wray
2009-Mar-10 00:30 UTC
[Puppet Users] Re: More fun with conditionals and structure...
RijilV wrote:> > 2009/3/9 Steve Wray <steve.wray@cwa.co.nz <mailto:steve.wray@cwa.co.nz>> > > > I want to stop ntpd on all domU and openvz virtual machines while > enabling > it on all dom0 and physical machines. > > I''ve been trying to get my head around this and searched through > documentation and examples but cannot find anything like this so far. > > If its running Debian Sarge then the init script is > /etc/init.d/ntp-server > > If its running Etch or Lenny then its /etc/init.d/ntp > > I''d thought that the "name" variable of ''service'' was supposed to > indicate > this? Or have I got my conditionals way wrong? Because the code I''ve > included doesn''t seem to do anything at all. Not even a syntax error... > > > class services { > > service { "ntp_service": > > name => $lsbdistcodename ? { > ''sarge'' => "ntp-server", > ''etch'' => "ntp", > ''lenny'' => "ntp", > }, > > case $virtual { > ''xenu'',''openvz'': > { > ensure => stopped, > enable => false, > pattern => "ntpd" > } > ''xen0'',''physical'': > { > ensure => running, > enable => true, > pattern => "ntpd" > } > } > } > } > > > > Kicks an error for me: > > $ puppet --parseonly test.pp > err: Could not parse for environment production: Syntax error at ''case''; > expected ''}'' at /raid/boaz/home/rijilv/test.pp:11 > > > How are you testing your manifests?So far, by running them in puppet in a test environment. In fact I grew suspicious that I wasn''t getting any errors or anything... so I did some other tests. What I did was take my code and comment out great chunks of it to see what would happen. So far the only thing that makes any difference is the first line. If I comment that out then I get errors from puppet, but nothing else seems to matter. -- Please remember that an email is just like a postcard; it is not confidential nor private nor secure and can be read by many other people than the intended recipient. A postcard can be read by anyone at the mail sorting office and expecting what is written on it to be private and secret is not realistic. Please hold no higher expectation of email. If you need to send confidential information in an email you need to use encryption. PGP is Pretty good for this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Anderson
2009-Mar-10 00:55 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Case statements don''t work inside of resource definitions. There are three ways I can think of do what you''re doing: 1. Use multiple inline selectors. (Very long and ugly.) 2. Write four different definitions of the NTP service and wrap them in a case statement (Not as long, but still ugly.) 3. Use if statements to set some variables, then use those in a single NTP service definition. (Shorter, maybe less ugly.) Here''s an example of number 3: case $lsbdistcodename { "sarge": { $ntp = "ntp-server" } default: { $ntp = "ntp" } } if ($virtual == "physical") or ($virtual == "xen0") { $ntp_enable = "true" $ntp_ensure = "running" } if ($virtual == "xenu") or ($virtual == "openvz") { $ntp_enable = "false" $ntp_ensure = "stopped" } service { $ntp: ensure => $ntp_ensure, enable => $ntp_enable, pattern => "ntpd" } This isn''t great, but if you have multiple services that differ in a similar fashion, you can define all the variables you need in a few statements at the top of your class and have one short definition for each service. -Josh On Mar 9, 2009, at 4:59 PM, Steve Wray wrote:> > I want to stop ntpd on all domU and openvz virtual machines while > enabling > it on all dom0 and physical machines. > > I''ve been trying to get my head around this and searched through > documentation and examples but cannot find anything like this so far. > > If its running Debian Sarge then the init script is /etc/init.d/ntp- > server > > If its running Etch or Lenny then its /etc/init.d/ntp > > I''d thought that the "name" variable of ''service'' was supposed to > indicate > this? Or have I got my conditionals way wrong? Because the code I''ve > included doesn''t seem to do anything at all. Not even a syntax > error... > > > class services { > > service { "ntp_service": > > name => $lsbdistcodename ? { > ''sarge'' => "ntp-server", > ''etch'' => "ntp", > ''lenny'' => "ntp", > }, > > case $virtual { > ''xenu'',''openvz'': > { > ensure => stopped, > enable => false, > pattern => "ntpd" > } > ''xen0'',''physical'': > { > ensure => running, > enable => true, > pattern => "ntpd" > } > } > } > } > > -- > Please remember that an email is just like a postcard; it is not > confidential nor private nor secure and can be read by many other > people > than the intended recipient. A postcard can be read by anyone at the > mail > sorting office and expecting what is written on it to be private and > secret > is not realistic. Please hold no higher expectation of email. > > If you need to send confidential information in an email you need to > use > encryption. PGP is Pretty good for this. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steve Wray
2009-Mar-10 02:03 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Joshua Anderson wrote:> Case statements don''t work inside of resource definitions. There are > three ways I can think of do what you''re doing: > > 1. Use multiple inline selectors. (Very long and ugly.) > 2. Write four different definitions of the NTP service and wrap them > in a case statement (Not as long, but still ugly.) > 3. Use if statements to set some variables, then use those in a single > NTP service definition. (Shorter, maybe less ugly.) > > Here''s an example of number 3: >[snip]> > This isn''t great, but if you have multiple services that differ in a > similar fashion, you can define all the variables you need in a few > statements at the top of your class and have one short definition for > each service.Ahhhh A lot of things in puppet now make more sense, thanks heaps!> > -Josh > > On Mar 9, 2009, at 4:59 PM, Steve Wray wrote: > >> I want to stop ntpd on all domU and openvz virtual machines while >> enabling >> it on all dom0 and physical machines. >> >> I''ve been trying to get my head around this and searched through >> documentation and examples but cannot find anything like this so far. >> >> If its running Debian Sarge then the init script is /etc/init.d/ntp- >> server >> >> If its running Etch or Lenny then its /etc/init.d/ntp >> >> I''d thought that the "name" variable of ''service'' was supposed to >> indicate >> this? Or have I got my conditionals way wrong? Because the code I''ve >> included doesn''t seem to do anything at all. Not even a syntax >> error... >> >> >> class services { >> >> service { "ntp_service": >> >> name => $lsbdistcodename ? { >> ''sarge'' => "ntp-server", >> ''etch'' => "ntp", >> ''lenny'' => "ntp", >> }, >> >> case $virtual { >> ''xenu'',''openvz'': >> { >> ensure => stopped, >> enable => false, >> pattern => "ntpd" >> } >> ''xen0'',''physical'': >> { >> ensure => running, >> enable => true, >> pattern => "ntpd" >> } >> } >> } >> } >> >> -- >> Please remember that an email is just like a postcard; it is not >> confidential nor private nor secure and can be read by many other >> people >> than the intended recipient. A postcard can be read by anyone at the >> mail >> sorting office and expecting what is written on it to be private and >> secret >> is not realistic. Please hold no higher expectation of email. >> >> If you need to send confidential information in an email you need to >> use >> encryption. PGP is Pretty good for this. >> > > > >-- Please remember that an email is just like a postcard; it is not confidential nor private nor secure and can be read by many other people than the intended recipient. A postcard can be read by anyone at the mail sorting office and expecting what is written on it to be private and secret is not realistic. Please hold no higher expectation of email. If you need to send confidential information in an email you need to use encryption. PGP is Pretty good for this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steve Wray
2009-Mar-15 20:15 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Joshua Anderson wrote:> Case statements don''t work inside of resource definitions. There are > three ways I can think of do what you''re doing: > > 1. Use multiple inline selectors. (Very long and ugly.) > 2. Write four different definitions of the NTP service and wrap them > in a case statement (Not as long, but still ugly.) > 3. Use if statements to set some variables, then use those in a single > NTP service definition. (Shorter, maybe less ugly.) > > Here''s an example of number 3: > > case $lsbdistcodename { > "sarge": { > $ntp = "ntp-server" > } > default: { > $ntp = "ntp" > } > } > > if ($virtual == "physical") or ($virtual == "xen0") { > $ntp_enable = "true" > $ntp_ensure = "running" > } > > if ($virtual == "xenu") or ($virtual == "openvz") { > $ntp_enable = "false" > $ntp_ensure = "stopped" > } > > service { $ntp: > ensure => $ntp_ensure, > enable => $ntp_enable, > pattern => "ntpd" > }Thats odd, last week I had thought this was working, now monday morning is here and I get: err: Could not retrieve configuration: Could not parse for environment production: Syntax error at ''(''; expected '')'' at /etc/puppet/manifests/classes/local_services.pp:12 It looks as if theres something wrong with the conditional still My code looks like this, which is same as yours but in a class: class local_services { case $lsbdistcodename { "sarge": { $ntp = "ntp-server" } default: { $ntp = "ntp" } } if ($virtual == "physical") or ($virtual == "xen0") { $ntp_enable = "true" $ntp_ensure = "running" } if ($virtual == "xenu") or ($virtual == "openvz") { $ntp_enable = "false" $ntp_ensure = "stopped" } service { $ntp: ensure => $ntp_ensure, enable => $ntp_enable, pattern => "ntpd" } } --~--~---------~--~----~------------~-------~--~----~ 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-Mar-15 20:53 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Hi> Thats odd, last week I had thought this was working, now monday morning is > here and I get: > > err: Could not retrieve configuration: Could not parse for environment > production: Syntax error at ''(''; expected '')'' at > /etc/puppet/manifests/classes/local_services.pp:12 > > It looks as if theres something wrong with the conditional stillthis error tells me that you aren''t running on 0.24.6, as I get the same with 0.24.5 but not on 0.24.7 . Please note that: http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#if-else mentions that such more complex boolean expressions are only support >0.24.6 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 -~----------~----~----~----~------~----~------~--~---
Steve Wray
2009-Mar-15 20:55 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Peter Meier wrote:> Hi > >> Thats odd, last week I had thought this was working, now monday morning is >> here and I get: >> >> err: Could not retrieve configuration: Could not parse for environment >> production: Syntax error at ''(''; expected '')'' at >> /etc/puppet/manifests/classes/local_services.pp:12 >> >> It looks as if theres something wrong with the conditional still > > > this error tells me that you aren''t running on 0.24.6, as I get the same > with 0.24.5 but not on 0.24.7 . > > Please note that: > http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#if-else > mentions that such more complex boolean expressions are only support >> 0.24.6Ok well, of neccessity, I am running in a mixed environment. Is there a nice way to get what I am trying to achieve in a mixed environment? Ie: a conditional with boolean conditionals ie something logically equivalent of: "if (a or b) then c"> > cheers pete > > >-- Please remember that an email is just like a postcard; it is not confidential nor private nor secure and can be read by many other people than the intended recipient. A postcard can be read by anyone at the mail sorting office and expecting what is written on it to be private and secret is not realistic. Please hold no higher expectation of email. If you need to send confidential information in an email you need to use encryption. PGP is Pretty good for this. --~--~---------~--~----~------------~-------~--~----~ 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-Mar-15 21:03 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Hi> Ok well, of neccessity, I am running in a mixed environment.I can understand that, on the otherside I would recommend to run a unique puppet environment and the custom packaging time you have to do for that is really worth the time.> Is there a nice way to get what I am trying to achieve in a mixed environment? > > Ie: a conditional with boolean conditionals ie something logically > equivalent of: > > "if (a or b) then c"with ugly statements: yes, with nice statements: not that I know. These new language features are exactly for that. :) I''m currently happily getting rid of these ugly statements. 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 -~----------~----~----~----~------~----~------~--~---
Steve Wray
2009-Mar-15 21:07 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Peter Meier wrote:> Hi > >> Ok well, of neccessity, I am running in a mixed environment. > > I can understand that, on the otherside I would recommend to run a > unique puppet environment and the custom packaging time you have to do > for that is really worth the time.Thats the objective. In order to converge on uniformity it will be nice to have puppets help... but in order to get puppet to help I have to get it to help in a diverse environment. Catch 22 kind of. I came up with this but I''m not really sure how correct it is: package { ntp-simple: ensure => $lsbdistcodename? { ''sarge'' => present, default => $virtual? { ''xenu'' => absent, ''xen0'' => present, ''openvz'' => absent, ''physical'' => present, default => present } } Any comment or advice? Is this going to do something unexpected?>> Is there a nice way to get what I am trying to achieve in a mixed environment? >> >> Ie: a conditional with boolean conditionals ie something logically >> equivalent of: >> >> "if (a or b) then c" > > with ugly statements: yes, with nice statements: not that I know. These > new language features are exactly for that. :) I''m currently happily > getting rid of these ugly statements. > > cheers pete > > >-- Please remember that an email is just like a postcard; it is not confidential nor private nor secure and can be read by many other people than the intended recipient. A postcard can be read by anyone at the mail sorting office and expecting what is written on it to be private and secret is not realistic. Please hold no higher expectation of email. If you need to send confidential information in an email you need to use encryption. PGP is Pretty good for this. --~--~---------~--~----~------------~-------~--~----~ 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-Mar-15 21:13 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Hi> Any comment or advice? Is this going to do something unexpected?looks fine to me. But didn''t test it. You can put into a file and test it with: puppet --parseonly foo.pp for any syntax problems. 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 -~----------~----~----~----~------~----~------~--~---
Steve Wray
2009-Mar-15 21:15 UTC
[Puppet Users] Re: More fun with conditionals and structure...
Peter Meier wrote:> Hi > >> Any comment or advice? Is this going to do something unexpected? > > looks fine to me. But didn''t test it. You can put into a file and test > it with: > > puppet --parseonly foo.pp > for any syntax problems.I am more concerned about logic problems :) Syntax problems are easy to spot! -- Please remember that an email is just like a postcard; it is not confidential nor private nor secure and can be read by many other people than the intended recipient. A postcard can be read by anyone at the mail sorting office and expecting what is written on it to be private and secret is not realistic. Please hold no higher expectation of email. If you need to send confidential information in an email you need to use encryption. PGP is Pretty good for this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---