Search code examples
puppet

class not found exception -puppet


I am trying to copy and execute the bash script from my puppet master to my puppet agent.

I have create a folder mymodule in /etc/puppet/modules/

[root@ip********* mymodule]# ls -l
total 0
drwxr-xr-x. 2 root root 30 Aug 26 15:58 files
drwxr-xr-x. 2 root root 20 Aug 26 16:57 manifests

[root@ip-*********** manifests]# ls -l
total 4
-rw-r--r--. 1 root root 372 Aug 26 16:57 init.pp

[root@ip-************* files]# ls -l
total 4
-rw-r--r--. 1 root root 151 Aug 26 15:13 my_bash_script.sh



 [root@ip-********** files]# cat my_bash_script.sh
        #!/bin/sh
        mv /usr/bin/node /usr/bin/bnode
        ln -s /usr/local/bin/node /usr/bin/node
        mv /usr/bin/npm /usr/bin/bnpm
        ln -s /usr/local/bin/npm /usr/bin/npm


 [root@ip-********* manifests]# cat init.pp
 class mymodule::mymodule{

 file {'/home/ec2-user/my_bash_script.sh':
      source => 'puppet:///modules/mymodule/files/my_bash_scrip.sh',
          mode => '755',
           }

    exec {'/home/ec2-user/my_bash_script.sh':
        refreshonly => 'true',
        require => File["/home/ec2-user/my_bash_script.sh"],
        subscribe => File["/home/ec2-user/my_bash_script.sh"],
      }
    }

and in my /etc/puppet/manifest/site.pp i am calling the class created in module.

[root@ip-*********** manifests]# cat site.pp
import 'mymodule'

node 'node1' {
    include "mymodule"
}

when i run from agent 'puppet agent -t'

i am getting the below error:

[root@ip-************8 /]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class mymodule for ip-**********8 on node ip-**********8
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

Solution

  • The init manifest (init.pp) of your class is expected to be defined as just the class name, like this:

    class mymodule {
    

    and not this:

    class mymodule::mymodule {
    

    so your inclusion of:

    include "mymodule"
    

    matches the class name.

    Also, your file resource has a syntax error and a typo. It should look like:

    file {'/home/ec2-user/my_bash_script.sh':
      source => 'puppet:///modules/mymodule/my_bash_script.sh',
      mode   => '755',
    }
    

    Check my answer to your previous question here: Executing bash script from puppet fails for more information about the source attribute and the Puppet URI.