[rudder-users] Get number of package to be upgraded (apt)

Nicolas Charles nicolas.charles at normation.com
Mon Aug 24 17:43:24 CEST 2015


Le 24/08/2015 15:36, Julien Escario a écrit :
> Hello,
Hello Julien !
> I'm currently trying to 'play' a bit with rudder to check if this could help us
> to manage our managed servers, all Linux.
>
> My first goal is to get the number of package that should be upgraded on a
> machine with 'apt-get upgrade'.
First, there is no (easy) way to centralize this information with 
Rudder; you can only get compliance status on rules you apply 
(Success/Repaired/Error), I'll elaborate on this below

> So, I made a technique 'Nb of packages upgradable by apt' which run :
> /bin/sh -c \'! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l\'
>
> On a machine, this return the number of packages that would have been upgraded
> by apt-get upgrade.
>
> Next, I made a directive using this technique. This is probably where I'm wrong.
> It seems there's nothing to specify except the technique used and rule to be
> applied.
> I checked the 'Global configuration for all nodes' rule and then goes to node ->
> Reports. I can see an item with my rule, directive, component and value.
> Value is my command and status is showing 'Missing'.
>
> By checking the log on the machine, here are the revelant lines (hope at least) :
> Aug 24 15:17:52 testmachine rudder[799]:
> /default/Nb_of_packages_upgradable_by_apt/methods/'method_call'/default/command_execution/commands/'/bin/sh
> -c '! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l''[0]: Finished command
> related to promiser '/bin/sh -c '! /usr/bin/apt-get -s upgrade | /bin/grep
> Inst|wc -l'' -- an error occurred, returned 1
> Aug 24 15:17:52 testmachine rudder[799]:
> /default/Nb_of_packages_upgradable_by_apt/methods/'method_call'/default/command_execution/commands/'/bin/sh
> -c '! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l''[0]: Q: ".../bin/sh -c
> '! /": 125
> Aug 24 15:17:52 testmachine rudder[799]: R: [ERROR] Promise could not be
> repaired, error encountered: Execute the command /bin/sh -c '! /usr/bin/apt-get
> -s upgrade | /bin/grep Inst|wc -l'
> Aug 24 15:17:53 testmachine rudder[799]:
> /default/Nb_of_packages_upgradable_by_apt/methods/'method_call'[0]: Method
> 'command_execution' failed in some repairs
>
> Not so good for a first try ;-)
>
> So is this possible and ... how ?
Unfortunately, you are bitten by the following bug : 
http://www.rudder-project.org/redmine/issues/5550 , which we though were 
fixed by another change, but was not
When you saved the Technique, the ' was escaped to \', which is not what 
we wanted.

The workaround I can suggest is to use the command

! /usr/bin/apt-get -s upgrade | /bin/grep Inst|wc -l

which would do the same.

The consequence will be that the Directive will return status:

  * Repaired if there are no package to upgrade
  * Error if there are packages to upgrade

The logic is that command_execution will return status "Repaired" for 
exit code 0, and "Error" for non exit code 0


Does that do what you want ?
>
> Thanks,
> Julien Escario (yeah, in France too)
Yeah \o/

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rudder-project.org/pipermail/rudder-users/attachments/20150824/5f96b746/attachment.html>


More information about the rudder-users mailing list