diff --git a/bench/commands/install.py b/bench/commands/install.py index 46460dd0..c4d5ea93 100644 --- a/bench/commands/install.py +++ b/bench/commands/install.py @@ -46,6 +46,10 @@ def install_nginx(user=None): if user: setup_sudoers(user) +@click.command('virtualbox') +def install_virtualbox(): + run_playbook('roles/virtualbox/tasks/main.yml', extra_vars=extra_vars) + @click.command('fail2ban') @click.option('--maxretry', default=6, help="Number of matches (i.e. value of the counter) which triggers ban action on the IP.") @click.option('--bantime', default=600, help="The counter is set to zero if no match is found within 'findtime' seconds.") @@ -61,4 +65,5 @@ install.add_command(install_nodejs) install.add_command(install_psutil) install.add_command(install_supervisor) install.add_command(install_nginx) -install.add_command(install_failtoban) \ No newline at end of file +install.add_command(install_failtoban) +install.add_command(install_virtualbox) diff --git a/playbooks/roles/virtualbox/tasks/debian_family.yml b/playbooks/roles/virtualbox/tasks/debian_family.yml new file mode 100644 index 00000000..853a1ae1 --- /dev/null +++ b/playbooks/roles/virtualbox/tasks/debian_family.yml @@ -0,0 +1,25 @@ +--- + +- name: Add VirtualBox to sources.list + apt_repository: + repo: deb https://download.virtualbox.org/virtualbox/debian {{ ansible_distribution_release }}contrib + state: present + +- name: Add apt signing key for VirtualBox for Debian >= 8 and Ubuntu >= 16 + apt_key: + url: https://www.virtualbox.org/download/oracle_vbox_2016.asc + state: present + when: (ansible_distribution == "Debian" and ansible_distribution_major_version >= "8") or (ansible_distribution == "Ubuntu" and ansible_distribution_major_version >= "16") + +- name: Add apt signing key for VirtualBox for Debian < 8 and Ubuntu < 16 + apt_key: + url: https://www.virtualbox.org/download/oracle_vbox.asc + state: present + when: (ansible_distribution == "Debian" and ansible_distribution_major_version >= "8") or (ansible_distribution == "Ubuntu" and ansible_distribution_major_version >= "16") + +- name: Install VirtualBox + apt: pkg={{ item }} update_cache=yes state=present + with_items: + - virtualbox-5.2 + +... diff --git a/playbooks/roles/virtualbox/tasks/main.yml b/playbooks/roles/virtualbox/tasks/main.yml new file mode 100644 index 00000000..80b1e939 --- /dev/null +++ b/playbooks/roles/virtualbox/tasks/main.yml @@ -0,0 +1,9 @@ +--- + +- include_tasks: debian_family.yml + when: ansible_os_family == 'Debian' + +- include_tasks: redhat_family.yml + when: ansible_os_family == "RedHat" + +... \ No newline at end of file diff --git a/playbooks/roles/virtualbox/tasks/redhat_family.yml b/playbooks/roles/virtualbox/tasks/redhat_family.yml new file mode 100644 index 00000000..35cf1741 --- /dev/null +++ b/playbooks/roles/virtualbox/tasks/redhat_family.yml @@ -0,0 +1,16 @@ +--- + +- name: Add VirtualBox Repository + yum_repository: + name: Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox + description: Official VirtualBox Yum Repo + baseurl: http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch + gpgkey: https://www.virtualbox.org/download/oracle_vbox.asc + gpgcheck: yes + +- name: Install VirtualBox + yum: name={{ item }} enablerepo=mariadb state=present + with_items: + - VirtualBox-5.2 + +... diff --git a/vm/build.py b/vm/build.py index a3b47b7e..8c637af3 100644 --- a/vm/build.py +++ b/vm/build.py @@ -1,22 +1,32 @@ """ Builds a vm and puts it in ~/public with a latest.json that has its filename and md5sum """ -import os -import subprocess -import json -import stat + +# imports - standard imports +import os +import json +import stat +from subprocess import check_output OUTPUT_DIR = 'output-virtualbox-ovf' PUBLIC_DIR = os.path.join(os.path.expanduser('~'), 'public') def main(): + install_virtualbox() + install_packer() build_vm() update_latest() move_to_public() cleanup() +def install_virtualbox(): + check_output(['bench', 'install', 'virtualbox']) + +def install_packer(): + pass + def build_vm(): - subprocess.check_call("./packer build vm.json", shell=True) + check_output("./packer build vm.json", shell=True) def move_to_public(): src = get_filepath() @@ -30,7 +40,7 @@ def update_latest(): json.dump(get_latest(), f) def get_latest(): - md5 = subprocess.check_output("md5sum {}".format(get_filepath()), shell=True).split()[0] + md5 = check_output("md5sum {}".format(get_filepath()), shell=True).split()[0] return { "filename": get_filename(), "md5": md5 diff --git a/vm/packer b/vm/packer deleted file mode 100755 index 26d83158..00000000 Binary files a/vm/packer and /dev/null differ