puppet 安装 jdk

$ sudo add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -s -c) partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

然后交互的选择 yes/no 进行安装。为了减少宝贵的人肉时间,有下面几种方式,最原始的方式:
$ ssh host "yes | apt-get -y install sun-java6-jdk"

除了上面这种方式,还可以通过 preseed 文件来将人肉部分的交互完全给简化掉,为此,需要在一台测试机上先人肉安装一次 sun-java6-jdk,以及 debconf-utils,接着可以查询 debconf 的 db 来确认那些进行交互的字段:
$ sudo debconf-get-selections  | grep java
sun-java6-bin   shared/accepted-sun-dlj-v1-1    boolean true
sun-java6-jdk   shared/accepted-sun-dlj-v1-1    boolean true
sun-java6-jre   shared/accepted-sun-dlj-v1-1    boolean true
sun-java6-jre   sun-java6-jre/stopthread        boolean true
sun-java6-jre   sun-java6-jre/jcepolicy note
sun-java6-bin   shared/error-sun-dlj-v1-1       error
sun-java6-jdk   shared/error-sun-dlj-v1-1       error
sun-java6-jre   shared/error-sun-dlj-v1-1       error
sun-java6-bin   shared/present-sun-dlj-v1-1     note
sun-java6-jdk   shared/present-sun-dlj-v1-1     note
sun-java6-jre   shared/present-sun-dlj-v1-1     note

上面这些字段最重要的就是开头的三行,将这些值插入到新的 deb db 中:
$ echo "sun-java6-jdk shared/accepted-sun-dlj-v1-1 select true" | debconf-set-selections
$ echo "sun-java6-jre shared/accepted-sun-dlj-v1-1 select true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive aptitude install -y -f sun-java6-jre sun-java6-bin sun-java6-jdk

或者将其重定向到一个文件比如叫 jdk6.seed,再执行 debconf-set-selections:
$ sudo debconf-set-selections jdk6.seed

这样再安装就不需要人工干预了,完全 auto 的方式如下,在此过程中还需要添加下 key:

class jdk{

    file {
      "/var/cache/debconf/jdk6.seeds":
      source => "puppet://$fileserver/jdk/jdk6.seeds",
      ensure => present;
    }  

    package {
        "sun-java6-jdk":
        responsefile => "/var/cache/debconf/jdk6.seeds",
        ensure       => installed;
        require      => [File["/var/cache/debconf/jdk6.seeds"],Exec["apt-get-update-jdk"]],
   
      }  
   
    exec {
        "apt-get-update-jdk":
        path => "/usr/bin",
        command => "apt-get update",
    refreshonly => true,
      }  

    exec {
        "apt-key":
        path => "/usr/bin",
        command => "apt-key adv --recv-key --keyserver keyserver.ubuntu.com D8D75E403EBCE749",
}

ref:
http://offbytwo.com/2011/07/20/scripted-installation-java-ubuntu.html