Primary goal is to add all puppet modules automatically, so that all dev-env's and prod-env could be started with one command. How can I install puppet modules through puppet manifest?
5 Answers
We've been happily using librarian-puppet to sync all 3rd party modules, it supports setting the modules' locations and versions. So production and dev run the exact same code. The usage is one liner
librarian-puppet install
In other cases we have a shell script that runs puppet two times, one time a minimal module that is only responsible for fetching the required modules, and then the full blown puppet flow when all modules are available.

- 18,524
- 17
- 70
- 98
-
i still can't understand this module purpose. does librarian also installs puppet modules not just custom one? when using git sub modules you can update all of them with one command? to install standard puppet modules I just created install-me.sh script. just want checkout & run method, without additional fuss. – holms Jun 02 '13 at 02:36
-
ok so this is basically same as librarian-chef. I've migrated to chef, but your answer is still valid – holms Nov 21 '13 at 11:40
-
it seems to me this doesn't actually answer the original question, as the module is *not* installed by the Puppet client, but by a third-party tool. So it requires users to install that library first, and you can't install that with Puppet! The best solution would be something builtin the Puppet client itself... – anarcat Oct 09 '15 at 16:10
The "Puppet module" type and provider does exactly that:
module { 'author/mymodule':
ensure => present,
}
module { 'puppetlabs/stdlib':
ensure => '2.6.0',
}
module { 'puppetlabs/stdlib':
ensure => present,
modulepath => '/etc/puppet/modules',
}
Recent versions of Puppet also have a puppet module
command that allows you to install arbitrary Puppet modules from the Puppet forge, example:
$ puppet module install rcoleman/puppet_module
Notice: Preparing to install into /home/anarcat/.puppet/modules ...
Notice: Created target directory /home/anarcat/.puppet/modules
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/home/anarcat/.puppet/modules
└── rcoleman-puppet_module (v0.0.3)
Other alternatives include:
r10k is now part of Puppet Entreprise 2015.03, so it can certainly be considered best practice.

- 5,605
- 4
- 32
- 38
-
1This looks easy and great, but has [issues](https://github.com/ryanycoleman/puppet_module_provider/issues/4) with newer version of puppet – vikas027 Oct 09 '15 at 16:01
-
1@vikas027 i have added other options that are now available, including the `puppet module` command and put a stronger emphasis on r10k. – anarcat Oct 09 '15 at 16:24
Here is an example of mine:
$module_stdlib = 'puppetlabs-stdlib'
exec { 'puppet_module_stdlib':
command => "puppet module install ${module_stdlib}",
unless => "puppet module list | grep ${module_stdlib}",
path => ['/bin', '/opt/puppetlabs/bin']
}
Where $module_stdlib is a module I whant to install.
The /bin
path is a path where the grep
comes from.
And the /opt/puppetlabs/bin
is a path where for the puppet binary exists in my installation.

- 2,084
- 1
- 22
- 32
Seems that writing module for installing puppet modules is possible - it'll be just wrapper for puppet module
tool. However, I didn't hear about such module yet.
I suppose this mechanism of installation is not popular because often you need to modify installed module, do some customizations. Practical tool for management of such modifications is version control system. For example, in our team we keep /etc/puppetlabs/puppet
directory in git repostitory. After installation of any module from Puppet Forge we add its files to version control and push it to remote git server. Our internally developed modules are also kept in this repository. This way, several puppet masters (dev and prod environments) are synchronized with this central repository and always have up-to-date versions of all modules.

- 2,943
- 1
- 23
- 26
I did this and it seemed to work
exec { 'puppet-fstab':
path => '/bin:/usr/bin',
command => 'puppet module install -i /usr/share/puppet/modules/AlexCline-fstab >>/tmp/err.log',
}

- 512
- 6
- 18
-
Of course I will just note that right after I got this to work, I realized that puppet has built in "mount" which does what I wanted to, so I removed this module, but hopefully this other points someone in the right direction. – alex.pilon Mar 27 '15 at 18:04