Ask Your Question
0

Install Packages after certain conditions met in puppet

asked 2016-11-27 06:06:42 -0500

karthik gravatar image

Hello All

I am beginner with puppet,I have been instructed to install some packages only after ensuring enough memory available

Forexample :apache to be installed on machine if 512 mb memory free on my machine

I have googled and couldn't find right track to accomplish this,hope "if" class could this but I am not sure,please guide me the methods to accomplish the task by hinting out right parameters.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-11-27 09:35:52 -0500

Hi,

You could do this by referencing a puppet fact - memoryfree_mb.

A rough example of a class that could implement this would be something like:

    class karthick {
        if $::memoryfree_mb > 500 {
             package { 'tmux':
                 ensure => 'installed',
        } 
     }
edit flag offensive delete link more

Comments

1

For newly written code I recommend usage of “modern” facter facts (if applicable): https://docs.puppet.com/facter/latest/core_facts.html#memory The legacy facts are kept in till the next major release (facter v4 in this case).

Kai Burghardt gravatar imageKai Burghardt ( 2016-11-27 12:17:22 -0500 )edit

Thanks sahumphries, May i know what does "$::" represents here ,if possible can you share me the relevant document page. I am a begineer,Please do apologise if it is basic one .

karthik gravatar imagekarthik ( 2016-11-28 02:21:19 -0500 )edit

the '::' is the scope operator, and if you put the scope operator before any variable names, then it implies 'top scope', which is where the old style facter facts live. as Kai mentioned, using the $facts[] hash is the new way / future standard, instead of the stringified way.

DarylW gravatar imageDarylW ( 2016-11-28 06:22:38 -0500 )edit

https://docs.puppet.com/puppet/latest/reference/lang_variables.html#qualified-variable-names

DarylW gravatar imageDarylW ( 2016-11-28 06:22:43 -0500 )edit
2

Using memory *free* may not be a good metric for installing packages on Linux servers. Unless you've got a LOT of extra RAM, you probably won't have much "free ram." Linux will use all of the memory for caching when it suits itself. 95-100% memory used it *expected* on a properly sized system.

bschonecker gravatar imagebschonecker ( 2016-11-29 05:34:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-11-27 06:06:42 -0500

Seen: 47 times

Last updated: Nov 27 '16