setting environment variables

2,337 views
Skip to first unread message

rekjed

unread,
Apr 7, 2008, 5:55:54 PM4/7/08
to Puppet Users
Hi all,

I'm running Puppet on FreeBSD and recently I started building my own
packages. I would like to set the PKGROOT variable on all hosts so
that packages are fetched from my server instead of freebsd.org. Is
it possible to set this with puppet?

I've read the suggestion on Trac [1], and it solves the problem when
puppet is run with an rc script, but it won't work when puppet is run
by hand. I sometimes run puppet by hand, when I don't have the time
to wait for the scheduled run to apply a change or when I'm
troubleshooting so this doesn't really fix it for me.

I also experimented with setting source in a package declaration:

in site.pp:
$pkg_source="http://pkg.blah.net/pub/FreeBSD/ports/$hardwaremodel/
packages-$kernelrelease/Latest"

in some class:
package {
"rsync":
ensure => present,
name => rsync,
source => $pkg_source,
}

This kind of works, but it means that I'd have to add source to all
my classes, at which point they break on the few Linux hosts that I've
got (I don't need to build packages for those at the moment). I'm
also not sure whenever it will know where to fetch the dependencies
form. So it can be done this way, but it's much more work I'd expect
from something simple as changing the package server. If I could
somehow set PKGROOT globally across the entire site it would kick some
serious ass. Any help is greatly appreciated.

Thanks,

Rek

[1] http://reductivelabs.com/trac/puppet/wiki/PuppetFreeBSD

James Turnbull

unread,
Apr 7, 2008, 6:52:48 PM4/7/08
to puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

rekjed wrote:

| This kind of works, but it means that I'd have to add source to all
| my classes, at which point they break on the few Linux hosts that I've
| got (I don't need to build packages for those at the moment). I'm
| also not sure whenever it will know where to fetch the dependencies
| form. So it can be done this way, but it's much more work I'd expect
| from something simple as changing the package server. If I could
| somehow set PKGROOT globally across the entire site it would kick some
| serious ass. Any help is greatly appreciated.

How about something like:

class pkgroot {

~ case $kernel {
~ linux: {}
~ default: { exec { "export PKGROOT='blah'": } }
~ }
}

Then include the class where required.

Or:

node "blah" {

~ case $kernel {
~ linux: {}
~ default: { include pkgroot }
~ }
}

and

class pkgroot {
~ exec { "export PKGROOT='blah'": }
}

Lots of different ways to skin that cat.

Regards

James Turnbull

P.S. Not tested and no coffee yet YMMV... :)

- --
James Turnbull (ja...@lovedthanlost.net)
- --
Author of:
- - Pulling Strings with Puppet
(http://www.amazon.com/gp/product/1590599780/)
- - Pro Nagios 2.0
(http://www.amazon.com/gp/product/1590596099/)
- - Hardening Linux
(http://www.amazon.com/gp/product/1590594444/)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH+qXA9hTGvAxC30ARAoSnAKCWYFP1bJheTcvtG3Oi+s462mJXxwCfWj0U
9s7Lrz2XZq+ULNiDWhdobeQ=
=zSJS
-----END PGP SIGNATURE-----

Luke Kanies

unread,
Apr 7, 2008, 9:56:33 PM4/7/08
to puppet...@googlegroups.com
On Apr 7, 2008, at 4:55 PM, rekjed wrote:

> If I could
> somehow set PKGROOT globally across the entire site it would kick some
> serious ass. Any help is greatly appreciated.


case $operatingsystem {
freebsd: {
Package { source => "/your/package/source" }
}
}

Done.

--
I cannot and will not cut my conscience to fit this year's fashions.
-- Lillian Hellman
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

David Schmitt

unread,
Apr 8, 2008, 2:28:22 AM4/8/08
to puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 08 April 2008, James Turnbull wrote:
> ~ exec { "export PKGROOT='blah'": }

Wouldn't that just set the variable in the subshell?

> P.S. Not tested and no coffee yet YMMV... :)


Regards, DavidS

- --
The primary freedom of open source is not the freedom from cost, but the free-
dom to shape software to do what you want. This freedom is /never/ exercised
without cost, but is available /at all/ only by accepting the very different
costs associated with open source, costs not in money, but in time and effort.
- -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFH+xCG/Pp1N6Uzh0URAjQvAJ4s3Y5/hMUSVHxPTU235+6ZQodpXACggqnY
AXxOXnrrpwTchl88mjwZoeM=
=cHjr
-----END PGP SIGNATURE-----

James Turnbull

unread,
Apr 8, 2008, 3:24:10 AM4/8/08
to puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David Schmitt wrote:
> On Tuesday 08 April 2008, James Turnbull wrote:
>> ~ exec { "export PKGROOT='blah'": }
>
> Wouldn't that just set the variable in the subshell?
>

Yes quite correct David - it would not work - had entirely ignored the
subshell execution. Luke provided a better and working example using
resource defaults:

case $operatingsystem {
freebsd: {
Package { source => "/your/package/source" }
}
}

Apologies for misleading anyone.

Regards

James Turnbull

- --
James Turnbull (ja...@lovedthanlost.net)
- --
Author of:
- - Pulling Strings with Puppet
(http://www.amazon.com/gp/product/1590599780/)
- - Pro Nagios 2.0
(http://www.amazon.com/gp/product/1590596099/)
- - Hardening Linux
(http://www.amazon.com/gp/product/1590594444/)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFH+x2a9hTGvAxC30ARAkJHAKCo7eeDJow26MNVUKzMmKnVEGR2XQCfe25S
5+HUmN/AJJp3MKOmN8tOtK4=
=0YzA
-----END PGP SIGNATURE-----

rekjed

unread,
Apr 8, 2008, 10:03:02 AM4/8/08
to Puppet Users
Hi Luke,

> case $operatingsystem {
> freebsd: {
> Package { source => "/your/package/source" }
>
> }
> }

This doesn't quite work on freebsd. As far as I know the source needs
to be a full path to the package so if I set source => "http://
pkg.blah.net" I get the following error:

err: //Node[mig]/rsync/Package[rsync]/ensure: change from absent to
present failed: Execution of '/usr/sbin/pkg_add http://pkg.blah.net'
returned 256: tar: Unrecognized archive format: Inappropriate file
type or format
tar: Error exit delayed from previous errors.
pkg_add: unable to open table of contents file '+CONTENTS' - not a
package?

I also tired setting the source => "http://pkg.blah.net/pub/FreeBSD/
ports/$hardwaremodel/packages-$kernelrelease/Latest/$name". This has
also failed:

err: //Node[mig]/rsync/Package[rsync]/ensure: change from absent to
present failed: Execution of '/usr/sbin/pkg_add
http://pkg.blah.net/pub/FreeBSD/ports/i386/packages-7.0-RELEASE/Latest/'
returned 256: tar: Unrecognized archive format: Inappropriate file
type or format
tar: Error exit delayed from previous errors.
pkg_add: unable to open table of contents file '+CONTENTS' - not a
package?

So it looks like setting the source won't work, unless I set it
explicitly in every package declaration...

Normally, If I don't set the source, puppet will install packages with
pkg_add -r. By default this will fetch packages from ftp.freebsd.org
unless a different server has been set in PACKAGEROOT. The handy
thing about PACKAGEROOT is that all I need to give it is the root of
the package server and, as long as the package repository is layout
properly, freebsd will take care of fetching the right package for the
right release/architecture. If I could somehow set PACKAGEROOT in the
environment before pupet runs I would be sorted. Otherwise there
seems to be no easy way to change the package server across the entire
site on freebsd. Would it be possible to add this functionality to
puppet in the future?

Cheers,


Rek

Phillip Scholz

unread,
Apr 8, 2008, 10:30:08 AM4/8/08
to puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don't know how this works with BSD - with linux one has to point to
the package itself:
source => "/local/path/to/apache2-common_1.3.8.deb",
for instance.

rekjed schrieb:

- --
Phillip Scholz
Junior Linux System-Administrator
IT Shared Hosting Linux - SaaS, Karlsruhe

1&1 Internet AG
Brauerstraße 48
D-76135 Karlsruhe

Tel. +49-721-91374-4818
phillip...@1und1.de
http://www.1und1.de/

Amtsgericht Montabaur HRB 6484

Vorstand: Henning Ahlert, Ralph Dommermuth,
Matthias Ehrlich, Andreas Gauger,
Thomas Gottschlich, Matthias Greve,
Robert Hoffmann, Markus Huhn,
Achim Weiss
Aufsichtsratsvorsitzender: Michael Scheeren
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)


Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH+4Fw1MyrzuZeshoRAm0gAJ9eJAMNP8tYWPHBAts67ozo+OY7gACdHATI
xa6L+JFVzj3InMl/HYiy/+8=
=8Fwn
-----END PGP SIGNATURE-----

Luke Kanies

unread,
Apr 8, 2008, 10:41:56 AM4/8/08
to puppet...@googlegroups.com
On Apr 8, 2008, at 9:03 AM, rekjed wrote:

> Normally, If I don't set the source, puppet will install packages with
> pkg_add -r. By default this will fetch packages from ftp.freebsd.org
> unless a different server has been set in PACKAGEROOT. The handy
> thing about PACKAGEROOT is that all I need to give it is the root of
> the package server and, as long as the package repository is layout
> properly, freebsd will take care of fetching the right package for the
> right release/architecture. If I could somehow set PACKAGEROOT in the
> environment before pupet runs I would be sorted. Otherwise there
> seems to be no easy way to change the package server across the entire
> site on freebsd. Would it be possible to add this functionality to
> puppet in the future?


Isn't there just a file on disk you can edit (using an exec, I assume)?

I think that's how people have solved it in the future.

--
It is odd, but on the infrequent occasions when I have been called upon
in a formal place to play the bongo drums, the introducer never seems
to find it necessary to mention that I also do theoretical physics.
-- Richard Feynman

Paul Lathrop

unread,
Apr 8, 2008, 1:41:13 PM4/8/08
to puppet...@googlegroups.com
You can set this in the init script that runs Puppet. Just export
PACKAGEROOT = your_package_root before you start Puppet.

rekjed

unread,
Apr 8, 2008, 4:18:35 PM4/8/08
to Puppet Users
Hi Paul,

> You can set this in the init script that runs Puppet. Just export
> PACKAGEROOT = your_package_root before you start Puppet.

Yeah, that's what puppet trac recommends, but it works only when
puppet is run from rc, which is not always true in my case.

I tried a number of things now and I think it's best to set this in /
etc/login.conf. I added PACKAGEROOT to setenv in the default login
class:

:setenv=MAIL=/var/mail/
$,BLOCKSIZE=K,FTP_PASSIVE_MODE=YES,PACKAGEROOT=http\c//pkg.blah.net:\

and rebuild the db:

sudo cap_mkdb /etc/login.conf

I also had to comment out a line in sudoers to preserve the package
related variables:

Defaults env_keep += "PKG_PATH PKG_DBDIR PKG_TMPDIR TMPDIR
PACKAGEROOT PACKAGESITE PKGDIR"

Now all users and daemons see the new package server, including
puppet.

Can I add this to the FreeBSD tips page on Trac?


Thanks for all the help,


Rek.

Paul Lathrop

unread,
Apr 8, 2008, 4:37:08 PM4/8/08
to puppet...@googlegroups.com
On Tue, Apr 8, 2008 at 1:18 PM, rekjed <rek...@gmail.com> wrote:
>
> Hi Paul,

> Can I add this to the FreeBSD tips page on Trac?

Awesome solution. Please feel free to update the wiki!

--Paul

Reply all
Reply to author
Forward
0 new messages