Ask Your Question
0

Puppet migration 3.8 to 5.4 - defined resource types not loading

asked 2018-02-16 14:22:33 -0500

wraukon gravatar image

Defined resource types are not loading for me, whether I have them in-line in the class or included in a .pp file as specified by the documentation.

For purposes of this problem, assume the node name in question to be 'my-testbox'. Please note that all classes without defined types will run perfectly fine.

When I run, I get the following:

Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Unknown resource type: 'ensure_dir' at /etc/puppetlabs/code/environments/production/modules/std_software/manifests/init.pp:31:3 on node my-testbox.my.domain
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

What am I doing wrong?!?

Stripped down, I have the following (everything is under /etc/puppetlabs/code/environments/production):

in manifests/site.pp:

stage { 'first': before Stage['main'] }
stage { 'final': require Stage['main'] }

class { 'std_software': stage => 'first', }

node /^my.*/ {
   class { 'sys_resource_limits': }
   class { 'sys_sudoers': }
}
 
modules/std_software/manifests/init.pp
class std_software {

  include std_software

  if ! defined (File['/etc/yum.repos.d/LOCAL.repo']) {
    notify { "*** You need to include yumrepo ***": }
  }

#  define ensure_dir ( $owner, $group, $mode, $but_first) {
#    if ! defined (File["${name}"]) {
#      file { "${name}":
#        ensure => directory,
#        owner => $owner, group => $group, mode => $mode,
#        require => $but_first,
#      }
#    }
#  }
#
#  define localfile ($owner, $group, $mode, $source) {
#    if ! defined (File["${name}"]) {
#      file { "${name}":
#       ensure => present,
#       owner => $owner, group => $group, mode => $mode,
#       source => "$source",
#      }
#    }
#  }

  ensure_dir { '/etc/yum.repos.d':
    owner => root, group => root, mode => '0755',
    but_first => Exec['/bin/true'],
 } 

  package { "rs-epel-release": 
    ensure => absent,
    before => Package['local-epel'],
  }

  package { "local-epel":
    ensure => present,
    name => "epel-release-${release}-${version}",
    require => [  File['/etc/yum.repos.d'],
                  File['/etc/yum.repos.d/LOCAL.repo'],
               ],
  }

  package { '7zip':
    name => 'p7zip',
    ensure => installed,
    require => Package['local-epel'],
  }

  package { 'telnet':
    ensure => installed,
    require => Package['local-epel'],
    install_options => ['--enablerepo=base'],
  }

  package { [ 'wget', 'rsync', 'vim-enhanced', 'jove', 'ntp', ]:
    ensure => installed,
    require => Package['local-epel'],
  }

  localfile { "/usr/local/bin/nmon":
    owner => root, group => root, mode => '0755',
    source => "puppet:///modules/std_software/nmon",
  }

}

modules/std_software/manifests/ensure_dir.pp

define std_software::ensure_dir (
                                      String $owner,
                                      String $group,
                                      String $mode,
                                      $but_first,
                                      )
{
  if ! defined (File["${title}"]) {
    file { "${title}":
      ensure => directory,
      owner => $owner, group => $group, mode => $mode,
      require => $but_first,
    }
  }
}

modules/std_software/manifests/localfile.pp

define std_software::localfile (
                                     String $owner,
                                     String $group,
                                     Integer $mode,
                                     String $source,
                                     )
{
  if ! defined (File["${name}"]) {
    file { "${name}":
      ensure => present,
      owner => $owner, group => $group, mode => $mode,
      source => "$source",
    }
  }
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-02-20 04:35:48 -0500

Henrik Lindberg gravatar image

Since puppet 4.0.0 you have to use fully qualified names when referencing classes/resources. Puppet has always named nested classes/resources with a fully qualified name - but the relative search for named things was changed in 4.0.0 due to the many mistakes and hard to figure out problems that caused.

edit flag offensive delete link more
0

answered 2018-02-16 15:08:49 -0500

wraukon gravatar image

[found the answer purely by sheer luck: I have to prepend the call with the class name as it is a class-local definition, i.e. I must create the defined reference via

  std_software::localfile { "/usr/local/bin/nmon":
    owner => "root", group => "root", mode => 0755,
    source => "puppet:///modules/std_software/nmon",
  }

I'm still not sure why this is necessary, but it works, so...(shrug)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-02-16 14:22:33 -0500

Seen: 279 times

Last updated: Feb 20