Skip to content

Commit

Permalink
Adds --enable-vbguest option (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliendufresne committed Jul 10, 2016
1 parent 27495fd commit 244babc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
10 changes: 9 additions & 1 deletion Vagrantfile.template
@@ -1,6 +1,14 @@
Vagrant.require_version ">= 1.8.4"
ENV["LC_ALL"] = "en_US.UTF-8"

if ${is_vbguest_enabled} and not Vagrant.has_plugin? "vagrant-vbguest"
if system "sudo vagrant plugin install vagrant-vbguest"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of vagrant-vbguest plugin has failed. Aborting."
end
end

Vagrant.configure(2) do |config|
config.vm.box = "${vagrant_box}"
config.vm.box_check_update = false
Expand All @@ -26,6 +34,6 @@ Vagrant.configure(2) do |config|
config.hostmanager.enabled = false
end
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
config.vbguest.auto_update = ${is_vbguest_enabled}
end
end
29 changes: 16 additions & 13 deletions config/default.md
@@ -1,13 +1,16 @@
| Ansible role | Vagrant box |
| ----------------------- | ------------------- |
| juliendufresne.influxdb | bento/debian-7.9 |
| juliendufresne.influxdb | bento/debian-7.10 |
| juliendufresne.influxdb | bento/debian-8.1 |
| juliendufresne.influxdb | bento/debian-8.2 |
| juliendufresne.influxdb | bento/debian-8.3 |
| juliendufresne.influxdb | bento/debian-8.4 |
| juliendufresne.influxdb | bento/ubuntu-12.04 |
| juliendufresne.influxdb | bento/ubuntu-14.04 |
| juliendufresne.influxdb | bento/ubuntu-15.04 |
| juliendufresne.influxdb | bento/ubuntu-15.10 |
| juliendufresne.influxdb | bento/ubuntu-16.04 |
| Ansible role | Vagrant box | enable-vbguest |
| ----------------------- | ------------------- | -------------- |
| juliendufresne.influxdb | bento/debian-7.9 | no |
| juliendufresne.influxdb | bento/debian-7.10 | no |
| juliendufresne.influxdb | bento/debian-8.1 | no |
| juliendufresne.influxdb | bento/debian-8.2 | no |
| juliendufresne.influxdb | bento/debian-8.3 | no |
| juliendufresne.influxdb | bento/debian-8.4 | no |
| juliendufresne.influxdb | bento/ubuntu-12.04 | no |
| juliendufresne.influxdb | bento/ubuntu-14.04 | no |
| juliendufresne.influxdb | bento/ubuntu-15.04 | no |
| juliendufresne.influxdb | bento/ubuntu-15.10 | no |
| juliendufresne.influxdb | bento/ubuntu-16.04 | no |
| juliendufresne.influxdb | bento/centos-6.7 | yes |
| juliendufresne.influxdb | geerlingguy/centos6 | yes |
| juliendufresne.influxdb | geerlingguy/centos7 | no |
5 changes: 4 additions & 1 deletion src/_run.sh
Expand Up @@ -19,6 +19,8 @@ clean_previous_vagrant_box() {
}

create_vagrantfile() {
local vagrant_box="$1"
local is_vbguest_enabled="$2"
local line=

while read -r line
Expand Down Expand Up @@ -58,6 +60,7 @@ run() {
local vagrant_box="$2"
local repository_directory="$3"
local is_verbose=$4
local is_vbguest_enabled="$5"
local testing_directory="$(mktemp -d)"

printf "# Testing ansible role \033[1;34m%s\033[0m in vagrant box \033[1;34m%s\033[0m\n" "${ansible_role}" "${vagrant_box}"
Expand All @@ -82,7 +85,7 @@ run() {

cd "${testing_directory}"

create_vagrantfile
create_vagrantfile "${vagrant_box}" "${is_vbguest_enabled}"
local report_file=$(ensure_report_file_exists "${repository_directory}" "${ansible_role}")

boot_vagrant_box ${is_verbose}
Expand Down
1 change: 1 addition & 0 deletions src/_usage.sh
Expand Up @@ -30,6 +30,7 @@ usage() {
e.g: '--config-file default' may be resolved with <repository_root>/config/default.md
-h, --help show this help.
-v, --verbose increase verbosity.
--enable-vbguest enable the vagrant-vbguest plugin and install it if needed.
--vagrant-box VAGRANT_BOX use specified vagrant box instead of default one. This option may be specified multiple times.
"
}
13 changes: 11 additions & 2 deletions test.sh
Expand Up @@ -16,6 +16,7 @@ IS_VERBOSE=false
VAGRANT_BOXES=
ANSIBLE_ROLES=
CONFIG_FILE=
ENABLE_VBGUEST="false"
while [[ $# -ge 1 ]]
do
case "$1" in
Expand All @@ -34,6 +35,9 @@ do
[ $? -ne 0 ] && { printf "$CONFIG_FILE"; exit 1; }
shift
;;
--enable-vbguest)
ENABLE_VBGUEST="true"
;;
-h|--help)
usage
exit 0
Expand Down Expand Up @@ -71,7 +75,7 @@ then
do
for VAGRANT_BOX in ${VAGRANT_BOXES}
do
run "${ANSIBLE_ROLE}" "${VAGRANT_BOX}" "${REPOSITORY_DIRECTORY}" ${IS_VERBOSE}
run "${ANSIBLE_ROLE}" "${VAGRANT_BOX}" "${REPOSITORY_DIRECTORY}" ${IS_VERBOSE} ${ENABLE_VBGUEST}
done
done
exit 0;
Expand All @@ -84,6 +88,11 @@ do
line=$(echo "${line}" | sed 's/^\s*|//' | sed 's/|\s*$//')
CURRENT_ANSIBLE_ROLE=$(echo "${line}" | cut -d '|' -f 1 | sed 's/^\s*//' | sed 's/\s*$//')
CURRENT_VAGRANT_BOX=$(echo "${line}" | cut -d '|' -f 2 | sed 's/^\s*//' | sed 's/\s*$//')
ENABLE_VBGUEST="false"
if [ "yes" == "$(echo "${line}" | cut -d '|' -f 3 | sed 's/^\s*//' | sed 's/\s*$//')" ]
then
ENABLE_VBGUEST="true"
fi

if [ -n "${ANSIBLE_ROLES}" ]
then
Expand Down Expand Up @@ -113,5 +122,5 @@ do

${FOUND} || continue

run "${CURRENT_ANSIBLE_ROLE}" "${CURRENT_VAGRANT_BOX}" "${REPOSITORY_DIRECTORY}" ${IS_VERBOSE}
run "${CURRENT_ANSIBLE_ROLE}" "${CURRENT_VAGRANT_BOX}" "${REPOSITORY_DIRECTORY}" ${IS_VERBOSE} ${ENABLE_VBGUEST}
done

0 comments on commit 244babc

Please sign in to comment.