how to write classes to install package from source

866 views
Skip to first unread message

CHEBRIAN

unread,
Jul 12, 2011, 6:14:55 AM7/12/11
to Puppet Users
Hi,

I want to write the class to install the packages from source .

Please suggest me how to achieve the following things .

1. download the source file and extract it .

2. to the make && make install and verify the installation

Regards

CHEBRIAN

Al @ Lab42

unread,
Jul 12, 2011, 6:19:02 AM7/12/11
to puppet...@googlegroups.com
You might find this define useful ( https://github.com/example42/puppet-modules/blob/master/common/manifests/defines/netinstall.pp ):
define netinstall (
    $url,
    $extracted_dir,
    $destination_dir,
    $owner = "root",
    $group = "root",
    $work_dir = "/var/tmp",
    $extract_command = "tar -zxvf",
    $preextract_command = "",
    $postextract_command = ""
    # $postextract_command = "./configure ; make ; make install"
    ) {

    $source_filename = urlfilename($url)

if $preextract_command {
    exec {
        "PreExtract $source_filename":
            command => $preextract_command,
            before => Exec["Extract $source_filename"],
            refreshonly => true,
    }
}

    exec {
        "Retrieve $url":
            cwd => "$work_dir",
            command => "wget $url",
            creates => "$work_dir/$source_filename",
            timeout => 3600,
    }

    exec {
        "Extract $source_filename":
            command => "mkdir -p $destination_dir ; cd $destination_dir ; $extract_command $work_dir/$source_filename",
            unless => "find $destination_dir | grep $extracted_dir",
            require => Exec["Retrieve $url"],
    }

if $postextract_command {
    exec {
        "PostExtract $source_filename":
            command => $postextract_command,
            cwd => "$destination_dir/$extracted_dir",
            subscribe => Exec["Extract $source_filename"],
            refreshonly => true,
            timeout => 3600,
            require => Exec["Retrieve $url"],
    }
}

}

vagn scott

unread,
Jul 13, 2011, 2:53:33 AM7/13/11
to puppet...@googlegroups.com
On 07/12/2011 06:19 AM, Al @ Lab42 wrote:
> command => "mkdir -p $destination_dir ; cd
> $destination_dir ; $extract_command $work_dir/$source_filename",
Nice. But I would suggest changing ';' to '&&'. That way, if the
mkdir or cd fail you don't end up
trying to extract the archive in the wrong directory.

command => "mkdir -p $destination_dir && cd $destination_dir &&
$extract_command $work_dir/$source_filename",

Also consider

unless => "test -d ${destination_dir }/${extracted_dir}",

or even better

creates => "${destination_dir }/${extracted_dir}",

for the repetition guard.

--
vagn

Peter Meier

unread,
Jul 13, 2011, 2:30:02 AM7/13/11
to puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/12/2011 12:19 PM, Al @ Lab42 wrote:
> You might find this define useful (
> https://github.com/example42/puppet-modules/blob/master/common/manifests/defines/netinstall.pp
> ):
>

or as a general best practice you might want to build your own packages.
They're much easier to handle!

~pete
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4dO2kACgkQbwltcAfKi3+5WQCfa35P0lZKGS8xYyitmfLt7Kiy
wUwAn0pnp4xscGeMNl3VA1Lo1xSygYh9
=ZGSf
-----END PGP SIGNATURE-----

Al @ Lab42

unread,
Jul 14, 2011, 10:03:44 AM7/14/11
to puppet...@googlegroups.com
Thanks for the suggestions, they are going to be merged.
That's a define I did various years ago that actually has been useful in various cases (I do agree that it's better to use packages, but sometimes this is the quickest and saner approach).

Al

KarthiKeyan. Kesavan

unread,
Jul 14, 2011, 1:08:31 PM7/14/11
to puppet...@googlegroups.com
Hi guys,

Thanks a lot for the suggestions .

Regards

K.Karthikeyan

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/EjT5lFqc31MJ.

To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Scott Smith

unread,
Jul 14, 2011, 4:04:16 PM7/14/11
to puppet...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages