Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1394 from oxyc/issue-1378
Browse files Browse the repository at this point in the history
Issue #1378: Auto-install Vagrant plugins
  • Loading branch information
geerlingguy authored Jun 2, 2017
2 parents 8586df6 + 0641cba commit 1e0f6b1
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ before_install:

script:
# Vagrantfile syntax check.
- 'rubocop ./Vagrantfile ./lib/drupalvm --except LineLength,Eval,MutableConstant,BlockLength,ConditionalAssignment,IndentArray,AlignParameters'
- 'rubocop ./Vagrantfile ./lib/drupalvm --except LineLength,Eval,MutableConstant,BlockLength,MethodLength,ConditionalAssignment,IndentArray,AlignParameters'

# Run tests.
- composer run-tests
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ Once the process is complete, you will have a Drupal codebase available inside t

Note: *If there are any errors during the course of running `vagrant up`, and it drops you back to your command prompt, just run `vagrant provision` to continue building the VM from where you left off. If there are still errors after doing this a few times, post an issue to this project's issue queue on GitHub with the error.*

### 3 - Configure your host machine to access the VM.
### 3 - Access the VM.

1. [Edit your hosts file](http://www.rackspace.com/knowledge_center/article/how-do-i-modify-my-hosts-file), adding the line `192.168.88.88 drupalvm.dev` so you can connect to the VM.
- You can have Vagrant automatically configure your hosts file if you install the `hostsupdater` plugin (`vagrant plugin install vagrant-hostsupdater`). All hosts defined in `apache_vhosts` or `nginx_vhosts` will be automatically managed. `vagrant-hostmanager` is also supported.
- The `auto_network` plugin (`vagrant plugin install vagrant-auto_network`) can help with IP address management if you set `vagrant_ip` to `0.0.0.0` inside `config.yml`.
2. Open your browser and access [http://drupalvm.dev/](http://drupalvm.dev/). The default login for the admin account is `admin` for both the username and password.
Open your browser and access [http://drupalvm.dev/](http://drupalvm.dev/). The default login for the admin account is `admin` for both the username and password.

Note: *By default Drupal VM is configured to use `192.168.88.88` as its IP, if you're running multiple VM's the `auto_network` plugin (`vagrant plugin install vagrant-auto_network`) can help with IP address management if you set `vagrant_ip` to `0.0.0.0` inside `config.yml`.*

## Extra software/utilities

Expand Down
2 changes: 2 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ end
require_ansible_version ">= #{vconfig['drupalvm_ansible_version_min']}"
Vagrant.require_version ">= #{vconfig['drupalvm_vagrant_version_min']}"

ensure_plugins(vconfig['vagrant_plugins'])

Vagrant.configure('2') do |config|
# Set the name of the VM. See: http://stackoverflow.com/a/17864388/100134
config.vm.define vconfig['vagrant_machine_name']
Expand Down
5 changes: 5 additions & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ vagrant_synced_folders:
vagrant_memory: 2048
vagrant_cpus: 1

# Ensure vagrant plugins are installed.
vagrant_plugins:
- name: vagrant-vbguest
- name: vagrant-hostsupdater

# Minimum required versions.
drupalvm_vagrant_version_min: '1.8.6'
drupalvm_ansible_version_min: '2.2'
Expand Down
11 changes: 11 additions & 0 deletions docs/extending/vagrantfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ config.vm.provider :virtualbox do |v|
end
```

### Automatically install Vagrant plugins

Drupal VM can be configured to ensure Vagrant plugins are installed by adding them to the `vagrant_plugins` list in your `config.yml` file.

```yaml
vagrant_plugins:
- name: vagrant-vbguest
- name: vagrant-hostsupdater
- name: vagrant-aws
```
### Example: Using the `vagrant-aws` provider

Add the following variables to your `config.yml`.
Expand Down
5 changes: 2 additions & 3 deletions docs/getting-started/installation-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ If the directory you are trying to mount is within an encrypted folder or volume
If encryption is not the issue then it's likely that either NFS isn't running correctly on your host, certain ports or protocols are being blocked by the system firewall, or you need to add additional mount options to your `vagrant_synced_folders` configuration. Try the following fixes:

1. On Ubuntu, if you get a message like `It appears your machine doesn't support NFS`, run `sudo apt-get install -y nfs-server`.
2. Install the `vagrant-vbguest` plugin, which will make sure you are running the latest version of the VirualBox Guest Additions inside the VM (this can solve many different problems!).
3. Make sure the `vboxnet` interfaces are not being blocked by your system firewall. For Fedora (and many flavors of Linux), check out this guide for more: [Get Vagrant's NFS working under Fedora 20](https://web.archive.org/web/20150706105420/http://blog.bak1an.so/blog/2014/03/23/fedora-vagrant-nfs/).
4. Add `mount_options: ['vers=3']` to your synced folder definition in config.yml after the other options like `local_path`, `destination`, and `type`.
1. Make sure the `vboxnet` interfaces are not being blocked by your system firewall. For Fedora (and many flavors of Linux), check out this guide for more: [Get Vagrant's NFS working under Fedora 20](https://web.archive.org/web/20150706105420/http://blog.bak1an.so/blog/2014/03/23/fedora-vagrant-nfs/).
1. Add `mount_options: ['vers=3']` to your synced folder definition in config.yml after the other options like `local_path`, `destination`, and `type`.

After attempting any of the above fixes, run `vagrant reload --provision` to restart the VM and attempt mounting the synced folder again, or `vagrant destroy -f && vagrant up` to rebuild the VM from scratch.

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/installation-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ If you are running Windows 7 and `vagrant up` hangs, you may need to upgrade Pow

## Hosts file updates

If you install either the `vagrant-hostsupdater` or `vagrant-hostmanager` plugin, you might get a permissions error when Vagrant tries changing the hosts file. On a macOS or Linux workstation, you're prompted for a sudo password so the change can be made, but on Windows, you have to do one of the following to make sure hostsupdater works correctly:
If you install either the `vagrant-hostsupdater` (installed by default unless removed from `vagrant_plugins` in your `config.yml`) or `vagrant-hostmanager` plugin, you might get a permissions error when Vagrant tries changing the hosts file. On a macOS or Linux workstation, you're prompted for a sudo password so the change can be made, but on Windows, you have to do one of the following to make sure hostsupdater works correctly:

1. Run PowerShell or whatever CLI you use with Vagrant as an administrator. Right click on the application and select 'Run as administrator', then proceed with `vagrant` commands as normal.
2. Change the permissions on the hosts file so your account has permission to edit the file (this has security implications, so it's best to use option 1 unless you know what you're doing). To do this, open `%SystemRoot%\system32\drivers\etc` in Windows Explorer, right-click the `hosts` file, and under Security, add your account and give yourself full access to the file.
Expand Down
6 changes: 0 additions & 6 deletions docs/getting-started/syncing-folders.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ vagrant_synced_folders:

See [this issue](https://github.com/geerlingguy/drupal-vm/issues/67) for more information.

### VirtualBox Guest Additions out of date

If you get errors when running `vagrant up` stating that your guest additions are out of date, you can fix this easily by installing the `vagrant-vbguest` plugin. Run the following command in the drupal-vm folder: `vagrant plugin install vagrant-vbguest`.

Otherwise, you will need to make sure you're using the officially supported `geerlingguy/ubuntu1404` box, which should _generally_ have the latest (or near-latest) guest additions installed. If not, please open an issue in the upstream project for building the base box: [`packer-ubuntu-1404`](https://github.com/geerlingguy/packer-ubuntu-1404).

### Permissions-related errors

If you're encountering errors where Drupal or some other software inside the VM is having permissions issues creating or deleting files inside a synced folder, you might need to either make sure the file permissions are correct on your host machine (if a folder is not readable by you, it probably also won't be readable when mounted via NFS!), or add extra configuration to the synced folders item (if using a sync method like `rsync`):
Expand Down
10 changes: 0 additions & 10 deletions docs/other/vagrant-virtualbox.md

This file was deleted.

27 changes: 27 additions & 0 deletions lib/drupalvm/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ def vagrant_provisioner
ansible_bin ? :ansible : :ansible_local
end

def ensure_plugins(plugins)
logger = Vagrant::UI::Colored.new
installed = false

plugins.each do |plugin|
plugin_name = plugin['name']
manager = Vagrant::Plugin::Manager.instance

next if manager.installed_plugins.key?(plugin_name)

logger.warn("Installing plugin #{plugin_name}")

manager.install_plugin(
plugin_name,
sources: plugin.fetch('source', %w[https://rubygems.org/ https://gems.hashicorp.com/]),
version: plugin['version']
)

installed = true
end

return unless installed

logger.warn('`vagrant up` must be re-run now that plugins are installed')
exit
end

def get_apache_vhosts(vhosts)
aliases = []
vhosts.each do |host|
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pages:
- 'Pre- and Post-Provision Scripts': 'extending/scripts.md'
- Other Information:
- 'Networking Notes': 'other/networking.md'
- 'Vagrant and VirtualBox': 'other/vagrant-virtualbox.md'
- 'Vagrant LXC provider': 'other/vagrant-lxc.md'
- 'Improving Performance': 'other/performance.md'
- 'Docker': 'other/docker.md'
Expand Down

0 comments on commit 1e0f6b1

Please sign in to comment.