Hi,
I''m having some ''strange'' issues with augeas and an
onlyif statement
This is my code
augeas { "classx_sysctl_shmmax":
    incl    => ''/etc/sysctl.conf'',
    lens    => ''Sysctl.lns'',
    changes => "set kernel.shmmax ${sysctl_kernel_shmmax}",
    onlyif  => "get kernel.shmmax < ${sysctl_kernel_shmmax}",
}
I only want to change the kernel.shmmax in /etc/sysctl.conf when the
value is greater than what is currently configured.
For example
kernel.shmmax defauls to 784009728 and I changed it manually to
784009729 (so +1)
=> When puppet runs, nothing needs to be done (as expected)
kernel.shmmax defaults to 784009728 and I changed it manually to
784009727 (so -1)
When puppet runs, it wants to change the value (as expected)
-kernel.shmmax = 784009727
+kernel.shmmax = 784009728
notice: /Stage[main]/Classx/Augeas[classx_sysctl_shmmax]/returns:
current_value need_to_run, should be 0 (noop)
So for now, everything looks fine, however ...
If I change the value to something really small, like from 784009728
to 84009728 (removed the first digit), pupppet does not want to change
it anymore.
What I can see is that puppet/augeas only evaluates values correctly
as long as the number of digits stays the same, so
100 is less than 101
101 is greater than 100
but 99 is greater than 100 ?!? :-(
Anyone an idea how I can configure augeas to do this correctly ??
Regards,
Rene
-- 
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.
FYI, I use puppet enterprise 2.0.2 and augeas 0.10 on RHEL6, but the same problem occured on Puppet 2.7.9 and augeas 0.9 on RHEL5/6 -- 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.
This is only a guess, but is Augeas doing a STRING comparison of the values
instead of a NUMERICAL one?
String-wise,   "7000" < "80" but numerically
it''s the other way around.
Can you try setting the current value to ''1'' and see if Augeas
wants to change it to 784009728.  If it does, then that''s the issue.
As to WHY it would be doing a string-wise comparison, I don''t know.  It
could be down to the version of  Augeas or the Puppet agent.  Try upgrading to
the latest and test it again...
Steve
Steve Shipway
University of Auckland ITS
UNIX Systems Design Lead
s.shipway@auckland.ac.nz
Ph: +64 9 373 7599 ext 86487
________________________________________
From: puppet-users@googlegroups.com [puppet-users@googlegroups.com] on behalf of
rvlinden [rene.vanderlinden73@gmail.com]
Sent: Wednesday, 15 February 2012 10:26 a.m.
To: Puppet Users
Subject: [Puppet Users] Augeas question a<b
Hi,
I''m having some ''strange'' issues with augeas and an
onlyif statement
This is my code
augeas { "classx_sysctl_shmmax":
    incl    => ''/etc/sysctl.conf'',
    lens    => ''Sysctl.lns'',
    changes => "set kernel.shmmax ${sysctl_kernel_shmmax}",
    onlyif  => "get kernel.shmmax < ${sysctl_kernel_shmmax}",
}
I only want to change the kernel.shmmax in /etc/sysctl.conf when the
value is greater than what is currently configured.
For example
kernel.shmmax defauls to 784009728 and I changed it manually to
784009729 (so +1)
=> When puppet runs, nothing needs to be done (as expected)
kernel.shmmax defaults to 784009728 and I changed it manually to
784009727 (so -1)
When puppet runs, it wants to change the value (as expected)
-kernel.shmmax = 784009727
+kernel.shmmax = 784009728
notice: /Stage[main]/Classx/Augeas[classx_sysctl_shmmax]/returns:
current_value need_to_run, should be 0 (noop)
So for now, everything looks fine, however ...
If I change the value to something really small, like from 784009728
to 84009728 (removed the first digit), pupppet does not want to change
it anymore.
What I can see is that puppet/augeas only evaluates values correctly
as long as the number of digits stays the same, so
100 is less than 101
101 is greater than 100
but 99 is greater than 100 ?!? :-(
Anyone an idea how I can configure augeas to do this correctly ??
Regards,
Rene
--
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 15/02/12 08:10, Steve Shipway wrote:> This is only a guess, but is Augeas doing a STRING comparison of the values instead of a NUMERICAL one? > > String-wise, "7000" < "80" but numerically it''s the other way around. > > Can you try setting the current value to ''1'' and see if Augeas wants to change it to 784009728. If it does, then that''s the issue. > > As to WHY it would be doing a string-wise comparison, I don''t know. It could be down to the version of Augeas or the Puppet agent. Try upgrading to the latest and test it again...I''m pretty sure you''re right with this. From a quick look at the code, then it''s simply not designed to work with integer values in settings. You''d need to file an RFE against Puppet for this, as the conditionals are implemented in the provider (not part of Augeas at all). -- Dominic Cleal Red Hat Consulting m: +44 (0)7817 878113 -- 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.
Here''s a patch to make puppet do integer comparison instead of string 
comparison if both strings are valid integers:
--- OLD/site_ruby/1.8/puppet/provider/augeas/augeas.rb  2013-09-19 
14:09:52.000000000 -0400
+++ NEW/site_ruby/1.8/puppet/provider/augeas/augeas.rb  2013-09-19 
16:23:48.000000000 -0400
@@ -164,6 +164,10 @@
     end
   end
 
+  def is_numeric?(s)
+    s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
+  end
+
   # Used by the need_to_run? method to process get filters. Returns
   # true if there is a match, false if otherwise
   # Assumes a syntax of get /files/path [COMPARATOR] value
@@ -179,10 +183,14 @@
 
     #check the value in augeas
     result = @aug.get(path) || ''''
-    case comparator
-    when "!="
+
+    if comparator == "<" and is_numeric?(result) and
is_numeric?(arg)
+      return_value = result.to_s.to_f < arg.to_s.to_f
+    elsif comparator == ">" and is_numeric?(result) and
is_numeric?(arg)
+      return_value = result.to_s.to_f > arg.to_s.to_f
+    elsif comparator == "!="
       return_value = (result != arg)
-    when "=~"
+    elsif comparator == "=~"
       regex = Regexp.new(arg)
       return_value = (result =~ regex)
     else
-- 
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+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.