Puppet 的 CPAN 安装程序找不到关系目标

Puppet 的 CPAN 安装程序找不到关系目标

基于以下代码这个博客在评论中我尝试为 Puppet 定义一些简单的 CPAN 安装功能,我正在尝试这样做:

class perl {
  define install-cpan () {
    exec { "cpan_load_${name}":
      command => "perl -I.cpan -MCPAN -e '\$ENV{PERL_MM_USE_DEFAULT}=1; install $name'",
      cwd => "/root",
      path => "/usr/bin:/usr/sbin:/bin:/sbin",
      unless => "perl -M$name -e 1",
    }
  }
  package { 'perl': ensure => installed }

}

perl::install-cpan { "Bundle::CPAN": }

但是我收到此错误:

err: Could not retrieve catalog from remote server: Could not intern
from pson: Could not convert from pson: Could not find relationship
target "Perl::Install-cpan[Bundle::CPAN]"

这是什么意思?我该如何解决?

答案1

我实际上已决定使用 cpanminus 而不是 cpan,并且正在使用:

# perl/manifests/init.pp

class perl {

  define installCPAN () {
    exec { "cpanLoad${title}":
      command => "cpanm $name",
      path    => "/usr/bin:/usr/sbin:/bin:/sbin",
      unless  => "perl -I.cpan -M$title -e 1",
      timeout => 600,
      require => Exec["initCPAN"],
    }
  }

  package { "perl": ensure => installed, require => Class["common"] }
  exec { "initCPAN":
    command =>  "wget -O - http://cpanmin.us | perl - --self-upgrade",
    path    => "/usr/bin:/usr/sbin:/bin:/sbin",
    creates  => "/bin/cpanm",
    require => [ Class["common"], Package["perl"] ],
  }
  # E.g.
  installCPAN { "JSON": }
  installCPAN { "JSON::XS": }
}

答案2

主要错误似乎是名称“install-cpan”中的“-”。不过,下面的方法确实有效,并且可以在以下位置找到 INIT_CPAN 命令如何自动化 CPAN 配置?

# perl/manifests/init.pp

class perl {

  define installCPAN () {
    exec { "cpanLoad${title}":
      command => "perl -MCPAN -e 'install(q[$name])'",
      cwd     => "/root",
      path    => "/usr/bin:/usr/sbin:/bin:/sbin",
      unless  => "perl -I.cpan -M$name -e 1",
      timeout => 600,
      environment => [
        "PERL_MM_USE_DEFAULT=1",
        "PERL_MM_NONINTERACTIVE=1",
        "AUTOMATED_TESTING=1",
      ],
    }
  }

  package { "perl": ensure => installed, require => Class["common"] }
  file { "initCPANcmd":
    source => "puppet://puppet/perl/INIT_CPAN",
    path   => "/root/INIT_CPAN",
    owner  => "root",
    mode   => 700,
  }
  exec { "initCPAN":
    command =>  "/root/INIT_CPAN",
    cwd     => "/root",
    path    => "/usr/bin:/usr/sbin:/bin:/sbin",
    creates  => "/root/.cpan/CPAN/MyConfig.pm",
    require => [ File["initCPANcmd"], Package["perl"] ],
  }

  perl::installCPAN { "Bundle::CPAN": require => Exec["initCPAN"] }

}

相关内容