Does Vagrant require a separate installation of Ansible? - vagrant

I need to distribute a Vagrant file to people who already have Vagrant installed.
What I am not sure about, is whether Vagrant requires a separate installation of Ansible or whether Ansible is automatically installed together with Vagrant.

Ansible must be installed on the machine in addition to Vagrant (and likely Virtualbox).
Stealing from my own project documentation.
Developer installation
Download and install Vagrant
Download and install VirtualBox
Install Ansible
OSX: brew install ansible
Ubuntu (see below)
Ansible from source for Ubuntu:
apt-get update
apt-get install python-pip python-dev git -y
pip install PyYAML jinja2 paramiko
git clone https://github.com/ansible/ansible.git
cd ansible
make install
Notes on Vagrant plus Ansible
Snippets from the Vagrantfile:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.provider "virtualbox" do |v|
v.memory = 4096 # we're running Java, need more than the 512mb default
v.customize ["modifyvm", :id, "--vram", "10"] # no graphics used.
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "../provisioning/vagrant.yml"
ansible.inventory_path = "../provisioning/hosts.ini"
ansible.limit = "vagrant"
We use the following for a vagrant-inventory.ini:
[vagrant]
192.168.111.222
And the vagrant.yml:
- hosts: vagrant
sudo: yes
pre_tasks:
(early init tasks here)
roles:
- role1
- role2
Hope this helps.

Related

apt-get command not found in Vagrant/Window

When I run vagran up command, I get the error apt-get command not found in vagrant, my pc is using window-10.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# VM Box
config.vm.box = "centos-7"
config.vm.network "private_network", ip: "192.168.33.100"
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
config.vm.provision "shell", path: "bootstrap.sh"
end
bootstrap.sh
sudo apt-get update
sudo apt-get apgrate
sudo apt-get install -y git
you're using a centos box
config.vm.box = "centos-7"
so you should use the yum package manager, apt is used for ubuntu family and is not compatible with the other os family (Debian vs Fedora)
To install git on centos replace your bootstrap script by
yum update
yum install -y git
Have you tried using yum and trying $ vagrant box update? Also, you can get more in depth logs by using $ vagrant up --debug or if you would like to save it to a file $ vagrant up --debug &> vagrant.log. I always recommend doing some VM house keeping as well by making sure all VMs are stopped then run $ vagrant reload --provision on the VM having the issues. As always, the best part of using Vagrant is the ability to wipe it and start over again.

Evaluation Error: Error while evaluating a Function Call, Could not find class ::apt-get::update for ubuntu-bionic.example.com

I'm getting the following error when running puppet on Vagrant/VirtualBox with the "ubuntu/bionic64" image:
Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::apt-get::update for ubuntu-bionic.example.com (file: /tmp/vagrant-puppet/manifests-846018e2aa141a5eb79a64b4015et6f3/default.pp, line: 2, column: 5) on node ubuntu-bionic.example.com
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Environment:
Vagrant 2.1.1
VirtualBox 5.2.16
Ubuntu Bionic 64
Puppet 5.4.0
Vagrantfile:
...
config.vm.box = "ubuntu/bionic64"
...
config.vm.provision "shell", inline: "apt-get update && apt-get install -y puppet"
config.vm.provision "puppet" do |puppet|
puppet.module_path = "puppet/modules"
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.options="--verbose --debug"
end
...
This same exact puppet configuration was working with the ubuntu/xenial64 box. The only thing that I changed was the config.vm.box line in my Vagrantfile (from config.vm.box = "ubuntu/xenial64" to config.vm.box = "ubuntu/bionic64". I've also confirmed that my module exists and I can see it on the vm in the /tmp directory.
I was able to fix the problem by renaming my apt-get module to apt_get.
Going from Ubuntu Xenial to Ubuntu Bionic takes Puppet from v3.8.5 to v5.4.0. Apparently, using hyphens in a module name isn't allowed (though it used to work).

How do I add PHPadmin to my bootstrap.sh commands?

I've been away from PHP nearly four years, I've been working in javascript and Node.JS instead. I have a memory of what tools I was comfortable working with.. it's a rusty memory how it all went together. I've followed Traversy's tutorial to get the LAMP box running
and have connected from MySQL WorkBench.
I'd like to use PHPAdmin, How do I add PHPadmin to my bootstrap.sh commands?
Installing phpMyAdmin On Vagrant
I like this version best, cause each domain has it's own /phpadmin, but I don't understand how he is editing the config file from inside bootstrap.sh
A super-simple Vagrant LAMP stack bootstrap (installable with one command)
I tried this one first, but got an error from the first curly brace, saying it didn't recognize the character..
bootstrap.sh
# Use single quotes instead of double quotes to make it work with special-character passwords
PASSWORD='12345678'
PROJECTFOLDER='myproject'
# Update Packages
apt-get update
# Upgrade Packages
apt-get upgrade
# Basic Linux Stuff
apt-get install -y git
# Apache
apt-get install -y apache2
# Enable Apache Mods
a2enmod rewrite
#Add Onrej PPA Repo
apt-add-repository ppa:ondrej/php
apt-get update
# Install PHP
apt-get install -y php7.2
# PHP Apache Mod
apt-get install -y libapache2-mod-php7.2
# Restart Apache
service apache2 restart
# PHP Mods
apt-get install -y php7.2-common
apt-get install -y php7.2-mcrypt
apt-get install -y php7.2-zip
# Set MySQL Pass
debconf-set-selections <<< 'mysql-server mysql-server/root_password password $PASSWORD'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $PASSWORD'
# Install MySQL
apt-get install -y mysql-server
# PHP-MYSQL lib
apt-get install -y php7.2-mysql
# Install phpmyadmin
# apt-get install phpmyadmin
# Restart Apache
sudo service apache2 restart
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Box Settings
config.vm.box = "ubuntu/trusty64"
# Provider Settings
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
# Network Settings
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "public_network"
# Folder Settings
config.vm.synced_folder ".", "/var/www/html", :nfs => { :mount_options => ["dmode=777", "fmode=666"] }
# Provision Settings
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
config.vm.provision "shell", path: "bootstrap.sh"
end

make it so vagrant doesn't run apt-get update automatically

When I do vagrant up on a new machine it tries do a sudo apt-get update before it runs of the provisioning lines. It appears that the process still exists however.
My Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.box_version = "1.5.0"
config.vm.box_check_update = false
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "vagrant"
config.vm.provision "shell", inline: <<-SHELL
apt-get -y install pdftk
SHELL
end
The problem is that some of the APT repos are returning 404's. This is causing output to stderr which appears to be preventing the shell provisioner winds up not running. Doing vagrant halt and then vagrant up a second time seems to do the trick but I'd rather not have to do 3x commands when 1x could be sufficient.
Anyway ideas how to disable this behavior?
Here's the output when I do vagrant up after doing vagrant destroy:
https://pastebin.com/4Hh49J7c
The errors in the logs are due to the vagrant vbguest plugin. This plugin will need to install the guest additions package for virtualbox matching your version and to do so some apt-get update are run.
You can disable this if this is causing issues during the creation of your VM
Vagrant.configure("2") do |config|
config.vbguest.auto_update = false
end
If you later want to align the version between virtualbox and the guest addition (this is recommended) you can run the following command
$ vagrant vbguest install

Does vagrant automatically install puppet?

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?
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).
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
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/
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).
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
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
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|
# ...
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.
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

Resources