Installing from source, not a package

828 views
Skip to first unread message

S Ahmed

unread,
Jul 17, 2011, 12:45:34 PM7/17/11
to puppet...@googlegroups.com
So I ran through a server setup on ec2, and have a text file of all the commands I used to get the server to where I wanted it.

I have a few questions now :)

I am running Ubuntu 10.10, and this is for a rails application.

1. I need to install Ruby Enterprise edition, which I had to do the following to get running: 

sudo apt-get install mysql-server libmysqlclient15-dev


mkdir -p downloads && cd downloads/


wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz


tar xzvf ruby-enterprise-1.8.7-2011.03.tar.gz

sudo apt-get install libreadline5-dev 

sudo apt-get install libssl-dev

sudo ./ruby-enterprise-1.8.7-2011.03/installer --auto /opt/ruby/


echo "export PATH=/opt/ruby/bin:$PATH" >> ~/.profile && . ~/.profile




The examples I have seen with puppet so far are mostly dealing with creating a node/class, and setting a particular service to be started etc.

How would I deal with this situation where I need:


i) setup apt-get dependancies

ii) download a file

iii) make the lib from source

iiii) modify my path



vagn scott

unread,
Jul 17, 2011, 2:33:41 PM7/17/11
to puppet...@googlegroups.com
On 07/17/2011 12:45 PM, S Ahmed wrote:
> So I ran through a server setup on ec2, and have a text file of all
> the commands I used to get the server to where I wanted it.

step 1: turn your list of commands into an idempotent script

#! /bin/sh

site=http://rubyenterpriseedition.googlecode.com/files
name=ruby-enterprise-1.8.7-2011.03
archive=$name.tar.gz
prepath="/opt/ruby/bin"
downloads=/root/downloads
wanted="
mysql-server
libmysqlclient15-dev
libreadline5-dev
libssl-dev
"

apt-get install $wanted

mkdir -p $downloads

[ ! -d $downloads/$archive ] && cd $downloads && wget $site/$archive
[ ! -d $downloads/$name ] && cd $downloads && tar xzf $archive

[ ! -f /opt/ruby/bin/ruby ] && ./$name/installer --auto /opt/ruby/
grep -q "$prepath" ~/.profile || echo "export PATH=$prepath:$PATH" >>
~/.profile

exit 0


step 2: puppetize it

class ruby_from_src {
$site
="http://rubyenterpriseedition.googlecode.com/files"
$name ="ruby-enterprise-1.8.7-2011.03"
$archive ="${name}.tar.gz"
$prepath ="/opt/ruby/bin"
$downloads ="/root/downloads"

$wanted = [
"mysql-server",
"libmysqlclient15-dev",
"libreadline5-dev",
"libssl-dev",
]

package { $wanted:
ensure => installed,
} ->

file { $downloads:
ensure => directory,
} ->

exec { "ruby from source download":
command => "wget ${site}/${archive}",
cwd => $downoads,
creates => "${dir}/${archive}",
} ->

exec { "ruby from source extract":
command => "tar xzf ${archive}",
cwd => $downloads,
creates => "${name}",
} ->

exec { "ruby from source install":
command => "./${name}/installer --auto /opt/ruby/",
cwd => $downloads,
creates => "/opt/ruby/bin/ruby",
}

file { "ruby from source PATH":
path => "/etc/profile.d/puppet_ruby_from_src.sh",
content => "PATH=${prepath}:\$PATH",
mode => 644,
}

}

step 3: run it and fix the bugs :-)

I have not tested it, so there might be bugs. But that's the general idea.
There's room for improvement though:

- parameterise the class so you can pass in the version, site, etc
- move some of the dependencies to other classes
mysql stuff belongs in a mysql_dev class
libssl-dev probably belongs in a network_dev class
*_dev classes should include a build_tools class

But, the biggest improvement would be to make your own package and
install that
instead of fiddling around with this low level stuff in the manifests.

--
vagn

Scott Smith

unread,
Jul 17, 2011, 3:04:33 PM7/17/11
to puppet...@googlegroups.com

Step 1:  don't do that

Step 2: make a package

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> 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.
>

S Ahmed

unread,
Jul 17, 2011, 3:05:03 PM7/17/11
to puppet...@googlegroups.com
wow, what can I say, thanks for guidance!

The last bit of what you said I don't understand:

"But, the biggest improvement would be to make your own package and install that
instead of fiddling around with this low level stuff in the manifests."

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.

Scott Smith

unread,
Jul 17, 2011, 3:07:59 PM7/17/11
to puppet...@googlegroups.com

You don't know what a package is?

On Jul 17, 2011 12:05 PM, "S Ahmed" <sahme...@gmail.com> wrote:
> wow, what can I say, thanks for guidance!
>
> The last bit of what you said I don't understand:
>
> "But, the biggest improvement would be to make your own package and install
> that
> instead of fiddling around with this low level stuff in the manifests."
>
>
>
> On Sun, Jul 17, 2011 at 2:33 PM, vagn scott <vagn...@gmail.com> wrote:
>
>> On 07/17/2011 12:45 PM, S Ahmed wrote:
>>
>>> So I ran through a server setup on ec2, and have a text file of all the
>>> commands I used to get the server to where I wanted it.
>>>
>>
>> step 1: turn your list of commands into an idempotent script
>>
>> #! /bin/sh
>>
>> site=http://**rubyenterpriseedition.**googlecode.com/files<http://rubyenterpriseedition.googlecode.com/files>
>> name=ruby-enterprise-1.8.7-**2011.03

>> archive=$name.tar.gz
>> prepath="/opt/ruby/bin"
>> downloads=/root/downloads
>> wanted="
>> mysql-server
>> libmysqlclient15-dev
>> libreadline5-dev
>> libssl-dev
>> "
>>
>> apt-get install $wanted
>>
>> mkdir -p $downloads
>>
>> [ ! -d $downloads/$archive ] && cd $downloads && wget $site/$archive
>> [ ! -d $downloads/$name ] && cd $downloads && tar xzf $archive
>>
>> [ ! -f /opt/ruby/bin/ruby ] && ./$name/installer --auto /opt/ruby/
>> grep -q "$prepath" ~/.profile || echo "export PATH=$prepath:$PATH" >>
>> ~/.profile
>>
>> exit 0
>>
>>
>> step 2: puppetize it
>>
>> class ruby_from_src {
>> $site ="http://**rubyenterpriseedition.**
>> googlecode.com/files <http://rubyenterpriseedition.googlecode.com/files>"
>> $name ="ruby-enterprise-1.8.7-2011.**03"
>> path => "/etc/profile.d/puppet_ruby_**from_src.sh",

>> content => "PATH=${prepath}:\$PATH",
>> mode => 644,
>> }
>>
>> }
>>
>> step 3: run it and fix the bugs :-)
>>
>> I have not tested it, so there might be bugs. But that's the general idea.
>> There's room for improvement though:
>>
>> - parameterise the class so you can pass in the version, site, etc
>> - move some of the dependencies to other classes
>> mysql stuff belongs in a mysql_dev class
>> libssl-dev probably belongs in a network_dev class
>> *_dev classes should include a build_tools class
>>
>> But, the biggest improvement would be to make your own package and install
>> that
>> instead of fiddling around with this low level stuff in the manifests.
>>
>> --
>> vagn
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Puppet Users" group.
>> To post to this group, send email to puppet...@googlegroups.com.
>> To unsubscribe from this group, send email to puppet-users+unsubscribe@**
>> googlegroups.com <puppet-users%2Bunsu...@googlegroups.com>.
>> For more options, visit this group at http://groups.google.com/**
>> group/puppet-users?hl=en<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...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.

vagn scott

unread,
Jul 17, 2011, 3:27:52 PM7/17/11
to puppet...@googlegroups.com
On 07/17/2011 03:05 PM, S Ahmed wrote:

The last bit of what you said I don't understand:

"But, the biggest improvement would be to make your own package and install that
instead of fiddling around with this low level stuff in the manifests."


My apologies.  I should remember to use standard English.

The biggest improvement to the code I just demonstrated is: Do something else.

I showed that code so I could answer your question directly, and because
I think it demonstrates some useful techniques.
However, there is a better way to solve the problem.
If you make a debian package, then you only need to install the package.

        class my_ruby {
                package { "my_ruby":
                        ensure => installed,
                }
        }

All the dependencies and environment setup would be done
by the package's install scripts.  Also, you would not leave
the download directory and all the other useless files on the server.
If you wanted to remove or upgrade the package all the details
would be handled by the package system.

It takes time to learn to make packages, so you can use the code
I showed you as a temporary solution.  But, for the future, you
should learn to make packages.

--
vagn


S Ahmed

unread,
Jul 17, 2011, 3:32:05 PM7/17/11
to puppet...@googlegroups.com
I do, I was confused as to whether that was puppet talk or debian/ubuntu related.

vagn scott

unread,
Jul 17, 2011, 4:39:00 PM7/17/11
to puppet...@googlegroups.com
Is suppose I should mention that, if you have an idempotent script like
the one mentioned,
you can use it directly. Again, not tested, so may bugs.


class ruby_from_src {

file { "/root/ruby_from_src.sh":
content => template("ruby_from_src/ruby_from_src.sh"),
before => Exec[ "/root/ruby_from_src.sh" ],
}

exec { "/root/ruby_from_src.sh":
creates => "/opt/ruby/bin/ruby",
}
}


--
vagn

chiggsy

unread,
Jul 18, 2011, 7:18:18 PM7/18/11
to puppet...@googlegroups.com
use fpm. You still should know how to make a package, but fpm will make one from a gem, or sources. If you are i a rush, that is.

John Shoemaker

unread,
Apr 12, 2012, 7:14:08 PM4/12/12
to puppet...@googlegroups.com
Is it possible to install packages to specific directories for most providers? (for example, passing --instdir to dpkg -i).
Reply all
Reply to author
Forward
0 new messages