This site is now 100% read-only, and retired.

Installing packages across multiple hosts with CFEngine

Posted by Steve on Wed 17 May 2006 at 14:31

We've described setting up a small network of hosts managed by CFEngine previously, but once installed what do you do with it? Well one common job for automating is to ensure that you have particular packages installed upon all your clients. With CFEngine this is simple.

If you're already using CFEngine you should be familiar with copying files from your central server to your client systems. What we're going to do to manage packages is to copy two files to each client:

  • autoapt.cfg
    • A configuration file specifying which files are installed upon each host.
  • autoapt.pl
    • The perl script which will do our installations for us.

Install these into your preferred directory, such as /etc/cfengine with something like this in your cfagent.conf:


copy::
 /var/lib/cfengine2/masterfiles/inputs/etc/cfengine/autoapt.cfg 
    dest=/etc/cfengine/autoapt.cfg 
    mode=644 owner=root group=root type=checksum define=autoapt

 /var/lib/cfengine2/masterfiles/inputs/etc/cfengine/autoapt.pl  
    dest=/etc/cfengine/autoapt.pl 
    mode=755 owner=root group=root type=checksum define=autoapt

Note: These lines are invalid. CFEngine doesn't like lines to be broken up like this. I've only done so to avoid wrapping issues.

Notice that we define a class once the copy has completed with the "define=autoapt" piece at the end of the line.

The class definition can now be used in a shellcommands section:

shellcommands:
  autoapt::
        "/etc/cfengine/autoapt.pl"

The result of this is that if the autoapt.cfg or autoapt.pl scripts have changed they will be copied to the client(s) and the newly installed autoapt.pl script will be executed.

autoapt.pl will read the configuration file /etc/cfengine/autoapt.cfg which we also copied, and process the file to choose which packages should be installed on each client node. The configuration file looks like this:

#
# This is the configuration file for the module:autoapt cfengine that
# installs/upgrades packages automatically.
#
# The format of non-comment lines is:
#
# name: space separated list of packages
#
# Name is either the hostname of a machine, or '*' to match any host.
# 

*: deborphan less vim sudo integrit syslog-ng
desk1: emacs21

In this example the packages less, vim, sudo, and deborphan will be installed upon all managed hosts - and the machine with hostname desk1 will have emacs21 installed upon it.

The autoapt files were originally taken from this site and updated to conform to the documentation. You can download both from here:

 

 


Also consider `Puppet'
Posted by legooolas (144.173.xx.xx) on Wed 17 May 2006 at 17:33
Puppet (http://reductivelabs.com/projects/puppet) is being written to come up with something better than cfengine, and it's pretty impressive already :)

The author has a blog at http://madstop.com/ and some fairly impressive ideas for the future development of it. I'm hoping to get people at my current workplace into using it, since it looks much more high-level and flexible than cfengine, and supports using apt-get to install packages automatically, etc.

(I'm not affiliated with it in any way, I've just been impressed with it more than I was with cfengine :)

[ Parent ]

Re: Also consider `Puppet'
Posted by Steve (82.41.xx.xx) on Wed 17 May 2006 at 17:37
[ View Weblogs ]

Several people have suggested I look at Puppet which is something I've been doing for the past few weeks.

On the plus side it is cleaner and has more flexability. On the down side it uses Ruby, isn't as easy to install on Sarge and is less well known.

I think that it will become much more popular when it becomes more mature - and then I can use cfengine to install it ;)

Steve

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Anonymous (201.141.xx.xx) on Wed 24 May 2006 at 14:36
this code gives me the following error. any input is apreciated. in the meantime, i'm ReadingTFM :)

thanks,k

cf:cfengine::/var/lib/cfengine2/inputs/cfagent.conf:47: Image loop: file/dir copies to itself or missing destination file
cf:cfengine::/var/lib/cfengine2/inputs/cfagent.conf:50: Image loop: file/dir copies to itself or missing destination file
cf:cfengine::/var/lib/cfengine2/inputs/cfagent.conf:50: Image loop: file/dir copies to itself or missing destination file
cf:cfengine::/var/lib/cfengine2/inputs/cfagent.conf:54: Image loop: file/dir copies to itself or missing destination file

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Steve (62.30.xx.xx) on Wed 24 May 2006 at 17:39
[ View Weblogs ]

I've not seen that error before, but I think I can see where it comes from.See how in the example I split the copy action into multiple lines? With the trailing "\"?

In cfengine you have to place it on one line. No splitting is allowed.

For example see the copy action in this sample file.

I'll update the article to make this clear. Sorry for the error.

Steve

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by kev (201.144.xx.xx) on Thu 25 May 2006 at 20:56
yea that fixed it. thanks for the quick reply. one more thing... i�m just learning the cfengine, so i could be wrong. but shouldn�t the copy class in the above example have one colon insead of two?

in the sample file its written like this:

copy:
/var/lib/cfengine2/masterfiles/inputs/etc/hosts dest=/etc/hosts server=server.my.flat mode=644 type=checksum


but in the article "Installing packages across multiple hosts with CFEngine" the example "copy" is written like this:

copy::
/var/lib/cfengine2/masterfiles/inputs/etc/cfengine/autoapt.cfg dest=/etc/cfengine/autoapt.cfg mode=644 owner=root group=root type=checksum define=autoapt

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Steve (62.30.xx.xx) on Thu 25 May 2006 at 21:24
[ View Weblogs ]

Yeah the sample file is just that - a sample. It isn't related to the article here, but I pointed it out as an example of a valid "copy" line.

I hope I didn't complicate things further..

Steve

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Anonymous (90.58.xx.xx) on Thu 14 Aug 2008 at 21:22
hi there,

splitting is permitted, I've found that cfengine does not support line arrangments, like having all the "=" placed with tabs.
Therefore, you can split your line just with CRLF, and make sure you use
key=value without spaces nor tabs just after key (you can before).

Cheers

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by ultraplexer (88.73.xx.xx) on Tue 11 Jul 2006 at 20:01
What is the advantage of autoapt.pl in comparison to the "actionsequence" called pakages. Cfengine is able to install software without any additional tools. If you define DefaultPkgMgr and DpkgInstallCommand, then you are able to install packages through cfengine. I know that the documentation is a little bit rare about this fact.


Daniel Guellmar

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Steve (62.30.xx.xx) on Tue 11 Jul 2006 at 20:05
[ View Weblogs ]

At the time when I tried it setting the package format to "dpkg" meant using Sun packages, rather than Debian ones.

With this script you can do more than just add packages too - you can uninstall them.

Steve

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Anonymous (138.67.xx.xx) on Tue 11 Jul 2006 at 22:47
How do you remove packages with this script? I don't see any documentation for it and don't see anywhere in the code that an apt-get remove is called.
I think that it could be added quite easily though. Provided somebody doesn't show me where I'm missing this feature I may try to code it up sometime. If I do where should I send or post it?

Mike Robbert

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Steve (62.30.xx.xx) on Tue 11 Jul 2006 at 23:08
[ View Weblogs ]

Sorry you are correct, please see the updated code here:

It does:

  • Software addition
  • Software removal
  • Software version checks

It can even work on CFEngine groups.

Steve

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Anonymous (138.67.xx.xx) on Wed 12 Jul 2006 at 23:41
Steve,
Thanks so much! That is exactly what I've been longing for. You didn't make all those changes last night did you? Those are some major changes from what was available before.
I can't wait to put this to work.

Mike

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Steve (62.30.xx.xx) on Thu 13 Jul 2006 at 06:19
[ View Weblogs ]

No, they were made a while back - but I forgot to update the code here.

Steve

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by siprbaum (131.188.xx.xx) on Wed 24 Jan 2007 at 22:52
Why don't you hand over $(allclasses) to autoapt.pl use this to get the groups nstead of parsing the cfagent.conf file?
I don't want to complain, but it took me over an hour to find out why
class = ( host1
host2
host3 )
isn't recognized, because it spans over several lines and the regex used doesn't match.

-Peter

PS: Sorry for the lame formating (no tabs), but I've no clue about html formating and the help mentions just a few HTML tags, but not what the do.

[ Parent ]

Re: Installing packages across multiple hosts with CFEngine
Posted by Steve (80.68.xx.xx) on Thu 25 Jan 2007 at 09:37
[ View Weblogs ]

Ignorance...

I wrote this before I started working with plugins, and knew about those kind of things.

Steve

[ Parent ]