CPAN installer for Puppet can’t find relationship target

cpanperlpuppet

Based on some code from this blog and in the comments I'm trying to define some simple CPAN install functionality for Puppet, and I'm trying this:

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": }

But I get this error:

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]"

What does this mean and how do I fix it?

Best Answer

I've actually decided to go with cpanminus over cpan, and am using:

# 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": }
}