[Pkg-puppet-devel] Bug#528737: Bug#528737: no easy way to 'pre-notify' or combine before and require

Russ Allbery rra at debian.org
Fri May 15 04:33:37 UTC 2009


Jayen Ashar <jayen at science.unsw.edu.au> writes:

> Hi, I'm running debian, and I'd like to preconfigure packages before
> installing them.  I was hoping there was a way to do this with
> before/require and subscribe/notify, but it gives a dependency cycle
> error.
>
> What I would like is for something like this:
>   exec {
>     "echo -e nullmailer      shared/mailname string  maths.unsw.edu.au\nnullmailer      nullmailer/adminaddr    string  jayen at science.unsw.edu.au\nnullmailer      nullmailer/relayhost    string  smtp.unsw.edu.au\n | debconf-set-selections":
>       path => "/sbin:/bin:/usr/sbin:/usr/bin",
>       before => Package[nullmailer],
>       subscribe => Package[nullmailer];
>   }
>   package {
>     "nullmailer": ensure => installed;
>   }
>
> to become something like this:
>   if package nullmailer is installed
>     do nothing
>   else
>     notify subscribed exec type
>       exec preconfiguration
>     install package

I don't think there's a way to express that currently.  Subscriptions
happen after the other resource has done its thing and you want it to
happen first.  You would need a verison of subscribe/notify that happens
beforehand, and I don't think Puppet has that.

The way you can work around that is to create a nullmailer class that
includes the exec and the package, make the package depend on the exec
(and you probably also want an unless clause on the exec so that it
doesn't run every time), and then include that module whenever you want
nullmailer.

Here's what we use for the debconf preseeding:

define preseed_debconf($answer, $source, $chroot="NONE") {
    $realname = "/etc/apt/$name"
    file { "$realname": source => $source; }

    case $chroot {
        NONE: {
            exec { "preseed $name":
                require => File["$realname"],
                command => "debconf-set-selections < $realname",
                unless  => "debconf-get-selections | grep -q -E $answer",
            }
        }
        default: {
            exec { "preseed $name in $chroot":
                require => File["$realname"],
                command => "chroot $chroot debconf-set-selections < $realname",
                unless  => "chroot $chroot debconf-get-selections | grep -q -E $answer",
            }
        }
    }
}

-- 
Russ Allbery (rra at debian.org)               <http://www.eyrie.org/~eagle/>





More information about the Pkg-puppet-devel mailing list