Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet can't find the module that I just installed

The problem that I found is that I can install Puppet modules successfully. For example:

[puppet@swarmcritic ~]$ puppet module install puppetlabs/mysql
Notice: Preparing to install into /home/puppet/.puppet/modules ...
Notice: Created target directory /home/puppet/.puppet/modules
Notice: Downloading from https://forge.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/home/puppet/.puppet/modules
└─┬ puppetlabs-mysql (v2.1.0)
  └── puppetlabs-stdlib (v4.1.0)

But when I try to invoke a module using a nodes.pp file like this:

 node 'example.com' {
    include '::mysql::server'
 }

Then I get an error like this:

[puppet@example mysql]$ sudo puppet apply ~puppet/puppet/manifests/site.pp
Error: Could not find class ::mysql::server for example.com on node example.com
Error: Could not find class ::mysql::server for example.com on node example.com

How can I fix it?

like image 264
user3150494 Avatar asked Dec 25 '22 14:12

user3150494


2 Answers

Puppet was installing the module in the .puppet directory tree of my home directory, but was not looking there when it came time to look for the module! Instead, it was ONLY looking in /etc/puppet/modules. It seems that, by default, it only looks there. If you want it to look in ~myusername/.puppet, you have to configure a path variable in /etc/puppet/puppet.conf or something.

To solve the problem, I didn't try to figure out how to modify the Puppet path. Instead, I installed the module explicitly into /etc/puppet/modules using the following command:

sudo puppet module install -i /etc/puppet/modules puppetlabs/mysql

Once this was done, the puppet apply command worked fine.

Further experimentation revealed that if you execute the Puppet module install command with no -i argument and root access, it will install the module into /etc/puppet/modules, but if you don't have root access, it will install it into ~myusername/.puppet/modules/. So if I had put a sudo in front of my original module installation command like this:

sudo puppet module install puppetlabs/mysql

then there wouldn't have been any problem. You don't have to specify the -i argument!

The entire problem arose because I chose to create a user account to hold all the puppet stuff rather than working in the root account. If I had worked in the root account, Puppet would (presumably) have installed the module into /etc/puppet/modules and there would have been no problem. It's only because I created a user account and then invoked the puppet module install command without sudo that the modules ended up in ~myusername/.puppet. Being a puppet novice, having modules installed in ~myusername/.puppet didn't seem like a bad idea. It seemed like a sensible place for the modules to be installed, particularly if one has created a user account to manage Puppet.

All this shouldn't put you off creating a user account to hold all your puppet configuration files. But if you do, remember to put sudo at the front of the installation command when you install modules.

Posted on behalf of the OP.

like image 63
2 revs Avatar answered Dec 31 '22 15:12

2 revs


It is worth noting that the modulepath can be found as follows :

# puppet config print modulepath
/etc/puppetlabs/puppet/modules:/opt/puppet/share/puppet/modules

More information can be found here ...

https://puppetlabs.com/learn/autoloading

like image 21
Rob Kielty Avatar answered Dec 31 '22 14:12

Rob Kielty