4

I'm setting up a Puppet master server for the first time. It's configured to use environments:

/etc/puppet/puppet.conf:

[main]
environmentpath = /var/opt/puppet/environments
basemodulepath = /var/opt/puppet/modules

Whenever I install a module, puppet module install foo, it get installed into my "production" environment's module directory. What I want to happen is for the module to be installed to /var/opt/puppet/modules unless I specify an environment with the --environment switch.

How do I do that?

4 Answers 4

3

As of the current Puppet version (v6.0):

By default, this command installs modules into the first directory in the Puppet modulepath, which defaults to $codedir/environments/production/modules.

That means you need to set the modulepath so that '/var/opt/puppet/modules' is the first directory in your modulepath. Since the modulepath setting can only be set in environment.conf, you need to edit your environment.conf for all of your environments.

nano -w /etc/puppetlabs/code/environments/{environment_name}/environment.conf

modulepath = '/var/opt/puppet/modules:/etc/puppetlabs/code/environments/production/modules:/etc/puppetlabs/code/modules:/opt/puppetlabs/puppet/modules'

BTW: For Puppet v6.0 '/etc/puppetlabs/code/modules' may be a better choice for a global modules directory.

2
  • I think this is stupid default behaviour. Why on earth would I ever want modules I install from forge available in only one environment? Great answer though, thank you! Jul 9, 2019 at 16:55
  • @AndyFoster you may want to see whether a module will work on your testing/staging environment before you use it on your production environment. I guess, the default is production, because Puppet comes with only one environment when you install it: production.
    – fkoksal
    Sep 8, 2019 at 20:53
0
puppet module --modulepath=/var/opt/puppet/modules install foo
2
  • I did say that I want them to install there by default. Is this thing really so difficult to use that I have to specify that switch every time? Jul 15, 2015 at 12:30
  • p.s. I've specified modulepath in the config prior to asking this question and it didn't work. 1) It complained about deprecation and 2) it still installed to production/modules. Jul 15, 2015 at 12:40
0

You are using environment config sections. So, you can set modulepath in each environment’s section of puppet.conf. Like...

[main]

--

environmentpath = /var/opt/puppet/environments

basemodulepath = /var/opt/puppet/modules

--

[production]

--

--

[dev]

--

--

If that setting is absent in a given environment, Puppet will fall back to the global value of the modulepath setting(/var/opt/puppet/modules). Or you can specify the separate module path for each directory sections. Hope you got the answer...

3
  • 1
    Well, no. I don't have any configuration specified for the individual environments. They are all using the defaults from [main], which is quoted in my question. But puppet module install foo is installing to /var/opt/puppet/environments/production/modules instead of /var/opt/puppet/modules. Jul 22, 2015 at 12:31
  • As you mentioned " It's configured to use environments" in the question, you are using directory environment and default environment is being created as production.... This is default behavior. So, you can define separate settings for every environment. If you are not defining any separate settings it will use /var/opt/puppet/environments/$environment/modules directory. Solution is, you need to define specific environment settings.. [production] modulepath=/var/opt/puppet/modules Jul 22, 2015 at 12:40
  • Hope you got the answer... :) Jul 22, 2015 at 12:45
0

Each environment can have its own 'modulepath' if you create an environment.conf file within the environment directory.

More information on environments can be found on the Puppet labs website here:

https://puppet.com/docs/puppet/latest/env_environments.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .