16

I have this in my Vagrantfile:

Vagrant.configure("2") do |config|
    config.vm.provision "puppet"
  end

Yet, when I run puppet --version I get :

[vagrant@vagrant-centos65 ~]$ puppet --version
-bash: puppet: command not found

Do I need to manually install puppet?

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • It depends on the Vagrant Box you are using. Some have Puppet preinstalled. Others, like CentOS, don't. – Stefan Lasiewski Nov 18 '17 at 01:31
  • There exists an enhancement request asking for this: https://github.com/hashicorp/vagrant/issues/10089 -- hopefully it'll happen at some point. – lindes Jan 21 '23 at 07:01

9 Answers9

18

No, (at the moment) Vagrant doesn't install it automatically.

So you either need to use a basebox which already has it installed (Puppet Labs provides boxes too), or you need to install it yourself. Probably the easiest way to install is to use shell provisioner before the puppet provisioner(s).

tmatilai
  • 4,071
  • 20
  • 24
7

In response to @tmatilai, I created this simple set up:

Vagrantfile:

Vagrant.configure(2) do |config|
  config.vm.box = "centos6.5_64"
  config.vm.provision "shell", path: "manifests/puppet.sh"
  config.vm.provision "puppet"
end

manifest/puppet.sh:

echo "Adding puppet repo"
sudo rpm -ivh https://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm
echo "installing puppet"
sudo yum install puppet -y
echo "ensure puppet service is running"
sudo puppet resource service puppet ensure=running enable=true
#echo "ensure puppet service is running"
#sudo puppet resource service puppetmaster ensure=running enable=true

echo "ensure puppet service is running for standalone install"
sudo puppet resource cron puppet-apply ensure=present user=root minute=30 command='/usr/bin/puppet apply $(puppet apply --configprint manifest)'

[vagrant@vagrant-centos65 home]$ puppet --version
3.4.2
Eric Francis
  • 23,039
  • 31
  • 88
  • 122
6

If you want to use a plugin, I made one that will automatically install Puppet from a version given in the Vagrantfile:

Vagrant.configure("2") do |config|

  config.puppet_install.puppet_version = :latest

end

This will also do a few cool tricks like make sure the puppet version you specify is a valid version and the like, full details here: https://github.com/petems/vagrant-puppet-install/

Peter Souter
  • 5,110
  • 1
  • 33
  • 62
  • Is there something that prevents this plugin from using anything greater than puppet 3.4.3? – Erik May 06 '15 at 00:16
  • Nope, it should work with whatever is the latest version of Puppet found on the package provider you use (without a specific version it just runs `apt-get install puppet`, `yum install puppet`, `pkg_add puppet` etc) – Peter Souter May 06 '15 at 04:44
4

Yes. I'm not sure what the state of Vagrant was at the time of some of these other answers, but these days puppet does not have to be installed via a shell provisioner, as Vagrant has a support puppet provisioner built right in.

At the most basic level, you can make sure puppet is supported on your box by adding provision "puppet" or provision "puppet_server" to your `Vagrantfile. For example:

#open config block (already present in your templated Vagrantfile)
Vagrant.configure(2) do |config|

  #...[snip]... other config.vm settings. Ex...
  # Ubuntu 14.04 LTS version
  #config.vm.box = "ubuntu/trusty64"

  # Make puppet avail inside machine
  config.vm.provision "puppet"


#close out Vagrant configuration for this instance
end

using puppet sets up puppet for local puppet apply (uses local manifests for configuring your machine), whereas using puppet_server hooks you up to a puppet master, and allows you to provision your vagrant box using a puppet server (a puppet master agent).

Mehdi Hosseini
  • 1,937
  • 1
  • 18
  • 29
Brian Vanderbusch
  • 3,313
  • 5
  • 31
  • 43
  • The question was how to install Puppet on a Vagrant box which does not have it already installed. As far as I know, Vagrant still doesn't install it automatically (only Chef), so you either have to use a provisioner (or plugin), or a pre-built box. – tmatilai Sep 23 '15 at 09:37
  • This answer is wrong. As @tmatilai said you must install puppet within the vm yourself. See my answer below for the appropriate doc reference. – Jesse Sanford Jun 16 '16 at 15:49
  • You are correct, buy I can't delete an accepted answer unfortunately. I messaged the OP but no luck – Brian Vanderbusch Jun 17 '16 at 21:42
4

As a few other people have already answered, there is no 'standard' that ensures a vagrant box comes pre-installed with Puppet.

By design, a vagrant box could have 'anything' pre-installed on it. Or it could just as easily have 'nothing' at all pre-installed. It all depends on who created it and what they included in the process of setting up the box.

If you find that your machine doesn't have Puppet pre-installed on it, you could also use one of the scripts that Mitchell Hashimoto has put together. See the following project on GitHub for details...

https://github.com/hashicorp/puppet-bootstrap

Danoz
  • 977
  • 13
  • 24
  • What's weird to me is that vagrant doesn't install it for you, though. This wouldn't be weird, except that _it does this for various other provisioners_! (It does this for at least chef and salt.) I don't suppose this is the place to request that the folks at HashiCorp change this, just... commenting in case others might be confused by the disparity. – lindes Jan 21 '23 at 06:27
2

At this point of time of writing, Vagrant does pre-installs puppet service. I ssh-ed into guest machine (used the box 'ubuntu/trusty64') and got following result :

vagrant@vagrant-ubuntu-trusty-64:~$ puppet --version
3.4.3
Tushar Goswami
  • 753
  • 1
  • 8
  • 19
  • 6
    As tmatilai said, it depends on where you get the Vagrant box from, some Vagrant boxes have Puppet pre-installed and some don't – Peter Souter Feb 24 '15 at 14:20
  • 1
    Agreed. In my ubuntu box. it came preconfigured, whereas in my colleague's experiment his centos box probably didnt came with puppet preinstalled – Tushar Goswami Feb 27 '15 at 04:36
2

As stated by others it depends on the box. For instance ubuntu/trusty64 comes with puppet pre-installed whereas ubuntu/xenial64 does not.

So to fix this for Ubuntu ubuntu/xenial64 adding an inline shell provisioner before the puppet provisioner is enough:

config.vm.box = "ubuntu/xenial64"

config.vm.provision :shell, :inline => 'apt-get -y update; apt-get -y install puppet'

config.vm.provision :puppet do |puppet|
# ...
conceptdeluxe
  • 3,753
  • 3
  • 25
  • 29
0

As of June 16 2016 Vagrant does NOT install puppet within the client VM as far as I can tell. I believe like it's sister project "packer" it expects you to do so explicitly. See: https://www.packer.io/docs/provisioners/puppet-masterless.html

Note: Puppet will not be installed automatically by this provisioner. This provisioner expects that Puppet is already installed on the machine. It is common practice to use the shell provisioner before the Puppet provisioner to do this.

Jesse Sanford
  • 607
  • 1
  • 8
  • 18
0
this worked for me:

put this inside your Vagrantfile - before your provisioning

$script = <<SCRIPT
echo I am installing puppet on guest 
sudo apt-get install -yq puppet=*
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: $script
end

This should install a puppet agent on the guest before you do other provisioning

serup
  • 3,676
  • 2
  • 30
  • 34