I'm using puppet to provision a vagrant (ubuntu based) virtual machine. In my script I need to:
sudo apt-get build-dep python-lxml
I know I can install the apt
puppet module so I can use:
apt::builddep { 'python-lxml': }
But I can't find any reference about installing a module from the script and how to include/require it. Seems to me that the puppet docs refer only to installing from the command line puppet tool
I also tried doing something like:
define build_dep($pkgname){ exec { "builddepend_$pkgname": commmand => "sudo apt-get build-dep $pkgname"; } } build_dep{ "python-imaging": pkgname => "python-imaging"; "python-lxml": pkgname => "python-lxml"; }
But puppet exited with an error on this. And also:
exec{"install apt module": command => "puppet module install puppetlabs/apt" } class { 'apt': require => Exec["install apt module"]} include apt apt::builddep { 'python-imaging': }
but got could not find declared class apt at..
any ideas? directions? I know I'm missing something obvious but can't figure this out.
EDIT: If I pre-install (with puppet module install
from the commandline) the apt:builddep
works fine. But I need puppet to handle the module downloading and installation. Some of the other work arounds also work for the basic use case but won't answer my main question.
In Puppet, all the programs which are written using Ruby programming language and saved with an extension of . pp are called manifests. In general terms, all Puppet programs which are built with an intension of creating or managing any target host machine is called a manifest.
To install a module from the Forge, run the puppet module install command with the long name of the module. The long name of a module is formatted as <username>-<modulename> . For example, to install puppetlabs-apache , run: puppet module install puppetlabs-apache.
A module is a collection of manifests and data (such as facts, files, and templates), and they have a specific directory structure. Modules are useful for organizing your Puppet code, because they allow you to split your code into multiple manifests.
I ran into this problem as well. The trick is to download the modules using a vagrant shell command before the puppet provisioner runs.
config.vm.provision :shell do |shell| shell.inline = "mkdir -p /etc/puppet/modules; puppet module install puppetlabs/nodejs; puppet module install puppetlabs/apache" end config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "site.pp" end
Order is important here, and since the puppet provisioner hasn't run the folder /etc/puppet/modules does not exist yet.
The reason I decided, like alonisser, to install the modules using the puppet module tool instead of using a module folder with the vagrant puppet provisioner was because I didn't want to have to download all of the dependencies of the modules I was going to use and store all of those modules in my source control. Running these two commands results in 5 dependencies that would otherwise sit in my git repository taking up space.
Here's what I did to make the puppet module install
command run at most once:
$script = <<EOF mkdir -p /etc/puppet/modules (puppet module list | grep puppetlabs-mysql) || puppet module install -v 2.1.0 puppetlabs/mysql EOF Vagrant::Config.run do |config| config.vm.provision :shell, :inline => $script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With