Re: [Puppet Users] String/Float comparison - Puppet and Facter

2015-08-04 Thread Mike Reed
Thanks you Martin, that is exactly what I needed.

Cheers,

m.

On Monday, August 3, 2015 at 11:07:09 PM UTC-7, Martin Alfke wrote:
>
>
> On 04 Aug 2015, at 00:39, Mike Reed > 
> wrote: 
>
> > Hello all, 
> > 
> > I've been trying to solve what seems to be a simple problem but have yet 
> to find the answer.   
> > 
> > I'm trying to do a comparison between the value of a fact and some 
> arbitrary value: 
> > 
> > if ($::class == 'workstation') and ($::kernelmajversion <= '3.11') { 
>
> You compare two strings. 
> Have you tried versioncmp function instead? 
> versioncmp($::kernelmajversion, ‘3.11’) 
>
> https://docs.puppetlabs.com/references/latest/function.html#versioncmp 
>
>
> > notify {"My Kernel version is <= ${kernel_test_version} and I'm 
> going to upgrade" : } 
> > 
> > file { 
> "/usr/src/linux-headers-${kernel_test_version}_${kernel_release_test_version}~precise1_all.deb"
>  
> : 
> >   mode   => '755', 
> >   ensure => 'present', 
> >   source => 
> "puppet:///modules/kernel/${kernel_test_version}_${kernel_release_test_version}~precise1_all.deb"
>  
>
> >  } 
> >   } 
> >   
> >   elsif ($::class == 'workstation') and ($::kernelmajversion >= '3.11') 
> { 
> > notify {"My Kernel version is >= ${kernel_test_version} so I don't 
> need to upgrade": } 
> >   } 
> > 
> > 
> > After invoking a puppet run, I can never get the evaluation of "if" to 
> actually take place and as a result, the elsif is invoked and regardless of 
> whether or not the kernel version is <= 3.11, the "if" statement is never 
> run.  From what I gather, this means that the evaluation of "if" is never 
> happening and the resulting elsif is automatically invoked. 
> > 
> > I've also seen some errors that pertain to string/float comparisons and 
> to my knowledge, facter data is coming back as a string and my version 
> number in the "if" statement (3.11) is a float and therefore can't be 
> compared due to comparison rules of different data types. 
> > 
> > Does anybody have some words of wisdom that may lead me to the correct 
> syntax for what I'm trying to achieve? 
> > 
> > Thanks in advance to the community for the help. 
> > 
> > Cheers, 
> > 
> > Mike 
> > 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Puppet Users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to puppet-users...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/5f9249a2-1bab-4f7e-84b5-f5fa6afd3ad7%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/7f1bfdb8-c1c5-4c9c-b7e8-d932425d700f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] String/Float comparison - Puppet and Facter

2015-08-03 Thread Martin Alfke

On 04 Aug 2015, at 00:39, Mike Reed  wrote:

> Hello all,
> 
> I've been trying to solve what seems to be a simple problem but have yet to 
> find the answer.  
> 
> I'm trying to do a comparison between the value of a fact and some arbitrary 
> value:
> 
> if ($::class == 'workstation') and ($::kernelmajversion <= '3.11') {

You compare two strings.
Have you tried versioncmp function instead?
versioncmp($::kernelmajversion, ‘3.11’)

https://docs.puppetlabs.com/references/latest/function.html#versioncmp


> notify {"My Kernel version is <= ${kernel_test_version} and I'm going to 
> upgrade" : }
> 
> file { 
> "/usr/src/linux-headers-${kernel_test_version}_${kernel_release_test_version}~precise1_all.deb"
>  :
>   mode   => '755',
>   ensure => 'present',
>   source => 
> "puppet:///modules/kernel/${kernel_test_version}_${kernel_release_test_version}~precise1_all.deb"
>  }
>   }
>   
>   elsif ($::class == 'workstation') and ($::kernelmajversion >= '3.11') {
> notify {"My Kernel version is >= ${kernel_test_version} so I don't need 
> to upgrade": }
>   }
> 
> 
> After invoking a puppet run, I can never get the evaluation of "if" to 
> actually take place and as a result, the elsif is invoked and regardless of 
> whether or not the kernel version is <= 3.11, the "if" statement is never 
> run.  From what I gather, this means that the evaluation of "if" is never 
> happening and the resulting elsif is automatically invoked.
> 
> I've also seen some errors that pertain to string/float comparisons and to my 
> knowledge, facter data is coming back as a string and my version number in 
> the "if" statement (3.11) is a float and therefore can't be compared due to 
> comparison rules of different data types.
> 
> Does anybody have some words of wisdom that may lead me to the correct syntax 
> for what I'm trying to achieve?
> 
> Thanks in advance to the community for the help.
> 
> Cheers,
> 
> Mike
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/5f9249a2-1bab-4f7e-84b5-f5fa6afd3ad7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/9800277A-848F-4303-9C5E-E155EBAB918E%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] String/Float comparison - Puppet and Facter

2015-08-03 Thread Mike Reed
Hello all,

I've been trying to solve what seems to be a simple problem but have yet to 
find the answer.  

I'm trying to do a comparison between the value of a fact and some 
arbitrary value:

if ($::class == 'workstation') and ($::kernelmajversion <= '3.11') {
notify {"My Kernel version is <= ${kernel_test_version} and I'm going 
to upgrade" : }

file { 
"/usr/src/linux-headers-${kernel_test_version}_${kernel_release_test_version}~precise1_all.deb"
 
:
  mode   => '755',
  ensure => 'present',
  source => 
"puppet:///modules/kernel/${kernel_test_version}_${kernel_release_test_version}~precise1_all.deb"
 }
  }
  
  elsif ($::class == 'workstation') and ($::kernelmajversion >= '3.11') {
notify {"My Kernel version is >= ${kernel_test_version} so I don't need 
to upgrade": }
  }


After invoking a puppet run, I can never get the evaluation of "if" to 
actually take place and as a result, the elsif is invoked and regardless of 
whether or not the kernel version is <= 3.11, the "if" statement is never 
run.  From what I gather, this means that the evaluation of "if" is never 
happening and the resulting elsif is automatically invoked.

I've also seen some errors that pertain to string/float comparisons and to 
my knowledge, facter data is coming back as a string and my version number 
in the "if" statement (3.11) is a float and therefore can't be compared due 
to comparison rules of different data types.

Does anybody have some words of wisdom that may lead me to the correct 
syntax for what I'm trying to achieve?

Thanks in advance to the community for the help.

Cheers,

Mike


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/5f9249a2-1bab-4f7e-84b5-f5fa6afd3ad7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.