I''m trying to write a script that runs command based on version of Redhat OS. For example, if the RHEL version is 6.0, it will run command. I was able to write file read script in ruby that would read file and execute but it didn''t seem to work in puppet script. Has anyone done something like this? $redhat_version_file = "/etc/redhat-release" $redhat_version = "File.read($redhat_version_file)" if ($redhat_version =~ /6.0/) { command } or $redhat_version_file = "/etc/redhat-release" if ( File.open($redhat_version_file).read().include? "6.0") {command} -- 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.
>I''m trying to write a script that runs command based on version of >Redhat OS. For example, if the RHEL version is 6.0, it will run >command. I was able to write file read script in ruby that would read >file and execute but it didn''t seem to work in puppet script. Has >anyone done something like this? > >Look at the pre-built $operatingsystemrelease fact before you try to roll your own. This email communication and any files transmitted with it may contain confidential and or proprietary information and is provided for the use of the intended recipient only. Any review, retransmission or dissemination of this information by anyone other than the intended recipient is prohibited. If you receive this email in error, please contact the sender and delete this communication and any copies immediately. Thank you. http://www.encana.com -- 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.
That''s good to know that there is ''$operatingsystemrelease'' built-in variable. But I have other applications with version files and I need to run specific class/command based on versions. Any suggestions how I should go around it? On Aug 8, 2:52 pm, "Kinzel, David" <David.Kin...@encana.com> wrote:> >I''m trying to write a script that runs command based on version of > >Redhat OS. For example, if the RHEL version is 6.0, it will run > >command. I was able to write file read script in ruby that would read > >file and execute but it didn''t seem to work in puppet script. Has > >anyone done something like this? > > Look at the pre-built $operatingsystemrelease fact before you try to > roll your own. > > This email communication and any files transmitted with it may contain confidential and or proprietary information and is provided for the use of the intended recipient only. Any review, retransmission or dissemination of this information by anyone other than the intended recipient is prohibited. If you receive this email in error, please contact the sender and delete this communication and any copies immediately. Thank you.http://www.encana.com-- 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.
Stephane Rossan
2011-Aug-09 00:23 UTC
Re: [Puppet Users] Re: Run command based on OS version
Facter can help you there. Puppet uses it to determine a bunch of facts about your server. You don''t have to have puppet to use it, if you use RHEL or Centos, you can get it through yum. If you run facter lsbdistrelease, will give your version. On 8/8/11 4:30 PM, "Steve" <some1youknow@gmail.com> wrote:>That''s good to know that there is ''$operatingsystemrelease'' built-in >variable. But I have other applications with version files and I need >to run specific class/command based on versions. Any suggestions how I >should go around it? > >On Aug 8, 2:52 pm, "Kinzel, David" <David.Kin...@encana.com> wrote: >> >I''m trying to write a script that runs command based on version of >> >Redhat OS. For example, if the RHEL version is 6.0, it will run >> >command. I was able to write file read script in ruby that would read >> >file and execute but it didn''t seem to work in puppet script. Has >> >anyone done something like this? >> >> Look at the pre-built $operatingsystemrelease fact before you try to >> roll your own. >> >> This email communication and any files transmitted with it may contain >>confidential and or proprietary information and is provided for the use >>of the intended recipient only. Any review, retransmission or >>dissemination of this information by anyone other than the intended >>recipient is prohibited. If you receive this email in error, please >>contact the sender and delete this communication and any copies >>immediately. Thank you.http://www.encana.com > >-- >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. > >-- 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.
Create a custom fact for your own needs. FYI $operatingsystemrelase (or some facts) may need the "*lsb*" packages. (I don''t have the exact name, redhat-lsb, I think, if redhat) On Mon, Aug 8, 2011 at 6:30 PM, Steve <some1youknow@gmail.com> wrote:> That''s good to know that there is ''$operatingsystemrelease'' built-in > variable. But I have other applications with version files and I need > to run specific class/command based on versions. Any suggestions how I > should go around it? > > On Aug 8, 2:52 pm, "Kinzel, David" <David.Kin...@encana.com> wrote: > > >I''m trying to write a script that runs command based on version of > > >Redhat OS. For example, if the RHEL version is 6.0, it will run > > >command. I was able to write file read script in ruby that would read > > >file and execute but it didn''t seem to work in puppet script. Has > > >anyone done something like this? > > > > Look at the pre-built $operatingsystemrelease fact before you try to > > roll your own. > > > > This email communication and any files transmitted with it may contain > confidential and or proprietary information and is provided for the use of > the intended recipient only. Any review, retransmission or dissemination of > this information by anyone other than the intended recipient is prohibited. > If you receive this email in error, please contact the sender and delete > this communication and any copies immediately. Thank you. > http://www.encana.com > > -- > 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. > >-- 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.
On Aug 8, 4:48 pm, Steve <some1youk...@gmail.com> wrote:> I''m trying to write a script that runs command based on version of > Redhat OS. For example, if the RHEL version is 6.0, it will run > command. I was able to write file read script in ruby that would read > file and execute but it didn''t seem to work in puppet script. Has > anyone done something like this? > > $redhat_version_file = "/etc/redhat-release" > $redhat_version = "File.read($redhat_version_file)" > if ($redhat_version =~ /6.0/) { command } > > or > > $redhat_version_file = "/etc/redhat-release" > if ( File.open($redhat_version_file).read().include? "6.0") {command}You haven''t provided enough information for me to fully understand what you already tried, but it sounds like maybe you wrote a Puppet manifest in Puppet''s Ruby DSL (as opposed to its traditional DSL). In that case, you need to understand that the manifest runs where the node''s catalog is compiled, which in a client / server setup is on the server. That is not what you want for the kind of problem you describe. In general, the way to provide node state information to Puppet is via facts -- custom facts if those you need are not already provided by Facter. These are fairly easy to write and distribute. John -- 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.