I started using Vagrant and Puppet recently, and i am having bit of difficulty getting puppet to work.
With puppet i want to change apache user and group to vagrant to solve permission issue when sharing the folder.
I want to do it by using following puppet config
class { "apache":
user => "vagrant",
group => "vagrant",
}
Reference : http://ryansechrest.com/2014/04/unable-set-permissions-within-shared-folder-using-vagrant-virtualbox/
For this i installed puppet on my host and guest machine, on host machine i added following cofig in Vagrantfile
config.vm.provision :puppet do |puppet|
puppet.manifests_path = 'puppet/manifests'
puppet.module_path = 'puppet/modules'
end
And created the file puppet/manifests/default.pp on host machine with following content
node 'node1' {
include apache
class { "apache":
user => "vagrant",
group => "vagrant",
}
}
When i run vagrant provision, i get the following error
==> default: Error: Could not find default node or by name with 'localhost' on node localhost
==> default: Error: Could not find default node or by name with 'localhost' on node localhost
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.
Where am i going wrong?
Just keep it simple:
For this i installed puppet on my host and guest machine,
you only need puppet to be installed on your guest machine, you can keep your host clean
you reference and define puppet/manifests/default.pp which is fine, just remove the node part
Package {
allow_virtual => true,
}
class { "apache":
user => "vagrant",
group => "vagrant",
}
include apache
can you confirm you have an apache module in your host puppet/modules or installed on the guest - you can have provision to run something like
#!/bin/bash
mkdir -p /etc/puppet/modules;
if [ ! -d /etc/puppet/modules/puppetlabs-apache ]; then
puppet module install puppetlabs-apache
fi
assuming you talk about this apache module, else replace with the module you're using if it comes from the forge
Related
The boxes were working fine. Then I halted one (the only one running at the time) and now I can't get either of them back up.
Running vagrant up [name] gives me the following error, regardless of which I pick or whether I leave it at vagrant up for them both to come up:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* A box must be specified.
Running latest version of Vagrant (1.7.4).
Here is my Vagrantfile in its entirety, comments included (just in case):
# Search for boxes here: https://atlas.hashicorp.com/boxes/search
# Refer to commands_vagrant.txt for command reference
Vagrant.configure("2") do |config|
# Globally defined variables
config.vm.synced_folder "./", "/var/www/public"
# CentOS 6.5, Apache 2.2.15, MySQL 5.5.36 (-u root), PHP 5.3.28
# Note: If PHP session keys don't work, set permissions to 777 (or other more restrictive, but this is guaranteed to work) on /var/lib/php/session
config.vm.define "php5dot3", primary: true do |php5dot3|
config.vm.box = "smallhadroncollider/centos-6.5-lamp"
config.vm.network :forwarded_port, guest: 80, host: 4567
end
# Ubuntu 14.04 (SSH pw: vagrant), Apache 2.4.12, MySQL 5.5.43 (-u root -p root), PHP 5.6.10
config.vm.define "php5dot6" do |php5dot6|
config.vm.box = "scotch/box"
config.vm.network :forwarded_port, guest: 80, host: 4568
end
end
Result of running vagrant status:
Current machine states:
php5dot3 poweroff (virtualbox)
php5dot6 poweroff (virtualbox)
Result of running vagrant global-status:
id name provider state directory
--------------------------------------------------------------------------
e1f3c85 default virtualbox poweroff /home/sam/Web
c588d51 php5dot6 virtualbox poweroff /home/sam/Web
4e71c50 php5dot3 virtualbox poweroff /home/sam/Web
'default' was the singular box I had in my Vagrantfile before I got multi-machines working last week. (Relevant?)
Result of running vagrant box list:
scotch/box (virtualbox, 2.0)
smallhadroncollider/centos-6.5-lamp (virtualbox, 1.0.0)
Any help would be appreciated, thanks.
Inside of your machine definitions, you need to use the variable name of that machine, instead of config. Try this out:
In the file below, I've changed config.vm to either php5dot3.vm or php5dot6.vm:
Vagrant.configure("2") do |config|
# Globally defined variables
config.vm.synced_folder "./", "/var/www/public"
# CentOS 6.5, Apache 2.2.15, MySQL 5.5.36 (-u root), PHP 5.3.28
# Note: If PHP session keys don't work, set permissions to 777 (or other more restrictive, but this is guaranteed to work) on /var/lib/php/session
config.vm.define "php5dot3", primary: true do |php5dot3|
php5dot3.vm.box = "smallhadroncollider/centos-6.5-lamp"
php5dot3.vm.network :forwarded_port, guest: 80, host: 4567
end
# Ubuntu 14.04 (SSH pw: vagrant), Apache 2.4.12, MySQL 5.5.43 (-u root -p root), PHP 5.6.10
config.vm.define "php5dot6", autostart:false do |php5dot6|
php5dot6.vm.box = "scotch/box"
php5dot6.vm.network :forwarded_port, guest: 80, host: 4568
end
end
I also added autostart:false to the definition of your php5dot6 box, which you can remove if you wish. (It just means that running vagrant up will only start the primary by default.
If you are getting this error with DigitalOcean, you may need their plugin:
vagrant plugin install vagrant-digitalocean
Installing the 'vagrant-digitalocean' plugin. This can take a few minutes...
Fetching: multipart-post-2.0.0.gem (100%)
Fetching: faraday-0.15.4.gem (100%)
Fetching: vagrant-digitalocean-0.9.3.gem (100%)
For someone that is having this issue now:
I had deleted my Vagrantfile before trying to destroy it. You need to run the vagrant destroy command from the right directory where the Vagrantfile for that process is.
Run vagrant ssh-config and look at the directory column.
If you, like me, deleted the file, do:
vagrant init
Then
vagrant destroy $id
P.S.: Use sudo if you have permission issues running those commands.
I am having trouble accessing files through Vagrant on Windows. I have been using it on OS X for quite some time and have my Vagrantfile setup correctly which works every time.
I have sent my colleague the same Vagrant file, he is on Windows and receives 'Permission Denied' when trying to access files through the browser.
Just to be clear, the permission errors are returned by the server when accessing 'dev.local' in the browser and not from Vagrant itself... it will be a configuration error on Windows or within the VM.
The VM is CentOS 6.5
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "chef/centos-6.5"
config.vm.network "private_network", ip: "192.168.33.21"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.provision :shell, :path => "install.sh"
config.vm.hostname = "dev.local"
config.vm.synced_folder ".", "/home", id: "vagrant", :nfs => false, :mount_options => ["dmode=777","fmode=777"]
config.ssh.insert_key = false
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
end
Can any Windows Vagrant users shed any light on this?
It was VBGuestAdditions out of date. The permission error was caused by not being able to sync to my local folder (which contained an index.php) so it was using the servers /home folder which didn't contain anything and since viewing directory structure is disabled it returned permission errors.
I had 4.X.X installed, and VirtualBox is on 5.X.X Here is the fix:
run command: vagrant plugin install vagrant-vbguest
the run vagrant up which may still throw an error as the plugin fails to copy a file.
vagrant ssh to get into the box and run the following command:
sudo ln -s /opt/VBoxGuestAdditions-5.X.X/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
Replace 5.X.X with the version of your VirtualBox.
logout and run vagrant reload
do a happy dance
I am writing a cookbook which will be run on Ubuntu. It will create a directory in home of the default user.
directory "/home/<default-user>/my-directory" do
owner <default-user>
end
The problem is, this default user is different across environments:
It is vagrant when running on virtual machine using Vagrant.
And it is ubuntu when running on EC2 instance.
What is a good practice to solve this kind of problem? And how to do it?
Thank you!
Make the user an attribute and set that according to your environment.
directory "/home/#{node[:my_app][:default_user]}/my-directory" do
owner node[:my_app][:default_user]
end
Then, on your attributes/default.rb file:
default[:my_app][:default_user] = 'ubuntu'
and on your Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provision "chef_solo" do |chef|
# ...
chef.json = {
"my_app" => {
"default_user" => "vagrant"
}
}
end
end
This will set your default user to ubuntu, but that will be overridden when running in the Vagrant VM.
Checkout the configuration entry config.ssh.username: http://docs-v1.vagrantup.com/v1/docs/config/ssh/username.html
I have been using http://www.puphpet.com successfully to generate vagrant+puppet environments for a number of projects. Then this week I got tasked with writing a prototype for a project using Laravel 4. Since I'm not going to be the one working on the project full time, I figured it would be best to make a VM environment for it that the next person can just clone for the repo. Not having much experience with Laravel 4 I got everything to run in the dev environment just fine. Then I tried to run the first migration and here the problems start with the app/storage file permissions.
1. app/storage must be writable by the web user
Fine, took out id: vagrant from the synced folder provisioning and set the owner & group to www-data like so:
config.vm.synced_folder "./www", "/var/www", owner: "www-data", group: "www-data"
2. Artisan can only be run from inside the vagrant box to have access to the DB
Fine, vagrant ssh and run artisan from the www folder.
3. app/storage & app/database have to be writable by the vagrant user in order to use migrations
Grrr, ok, added the following awful piece of code to the vagrant file (note, tried to do this in Puppet first and it didn't take):
config.vm.provision :shell, :inline =>
"usermod -a -G www-data vagrant"
4. app/storage & app/database are not writeable by the group
Argh!!! Ok, let's try this Puppet directive:
file { "/var/www/app/storage":
source => "/var/www/app/storage/",
mode => 0775,
ensure => 'directory',
owner => 'www-data',
group => 'www-data',
recurse => true
}
Nope, doesn't work. Tried to do the same with the Puppet exec {} directive to no effect. It seems that permissions for the vagrant synced folder are set by the host machine, not the guest.
Finally ended up manually changing the permissions for the folder in the host machine. Is there any simpler way to do this? I would really just like to be able to give the next dev a worry free environment they can clone from the repo, not have them re-setup everything after cloning.
UPDATE
We've figured out that if we change the Apache run user, vagrant doesn't override it on reload. So we've done that manually and it's working better than changing the synced folder's permissions & owner. Now we're just trying to figure out how to make that change manually in Puppet.
After some discussion on Twitter, figured out the following:
There's a constraint from VirtualBox on vagrant that does not allow you to set permissions for the synced folder from inside the guest OS. See this issue on github.
You can use the following code to set the synced folder permissions from the vagrant file:
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
Or you can change the Apache runtime user to vagrant from the puppet manifest like so:
exec { "change_httpd_user":
command => "sed -i 's/www-data/vagrant/g' /etc/apache2/envvars",
onlyif => "/bin/grep -q 'www-data' '/etc/apache2/envvars'",
notify => Service['apache2'],
require => Package['apache2'],
}
file { "/var/lock/apache2":
ensure => "directory",
owner => "vagrant",
group => "vagrant",
require => Exec['change_httpd_user'],
}
Or any combination of the above
I'm not using pupphet in my setup and I came up with 2 solutions:
(1) In my bootstrap.sh file:
sudo sed -i 's/APACHE_RUN_USER=.*/APACHE_RUN_USER=vagrant/g' /etc/apache2/envvars
sudo sed -i 's/APACHE_RUN_GROUP=.*/APACHE_RUN_GROUP=www-data/g' /etc/apache2/envvars
(2) Im my VagrantFile:
config.vm.synced_folder "./", "/vagrant", id: "vagrant-root" , :owner => "vagrant", :group => "www-data"
config.vm.synced_folder "./app/storage", "/vagrant/app/storage", id: "vagrant-storage",
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
config.vm.synced_folder "./public", "/vagrant/public", id: "vagrant-public",
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
Have a look at this section of the Vagrant documentation http://docs.vagrantup.com/v2/synced-folders/basic_usage.html
I want puppet to look for hiera.yaml in /etc but it's looking for it in /etc/puppet. I put a line into puppet.conf:
hiera_config = /etc/hiera.yaml
But still gives me the hiera.yaml update warning when I run the script.
I'm running the script from Vagrant 1.2.2. Using puppet 3.2.2
I'm running Centos 6.4 in a vm.
I found that the puppet provisioner in vagrant now support hiera_config_path which does exactly what is desired.
config.vm.provision :puppet do |puppet|
# path on host machine to hiera.yaml
puppet.hiera_config_path = '/Users/me/vms/hiera/hiera.yaml'
# This sets the relative path for hiera data directories
puppet.working_directory = '/Users/me/vms/hiera'
end
This is documented in Vagrant: Up and Running but I didn't find it until I started looking into the vagrant source to implement this feature myself.
Hmmm... On Vagrant 1.2.2 and Puppet 3.2.3, I am able to set hiera_config in puppet.conf without problems. I would double-check that you are editing /etc/puppet.conf on the Vagrant vm, not on the host machine, and that the hiera_config line is the [main] block, not just in the [master] block.
If both of those conditions are true and it is still not working, you might try explicitly setting hiera_config in your Vagrantfile:
config.vm.provision :puppet do |puppet|
...
puppet.options = '--hiera_config=/etc/hiera.yaml'
end
Good luck!
Puppet provisioning runs as root user, not vagrant, so that's why it doesn't take notice of your puppet.conf in /vagrant.
If you run puppet config print inside the vm from user vagrant and root you see ALL puppet config settings per user and compare.