From d107a63716eba90216a0edd0c7cca60f8040d881 Mon Sep 17 00:00:00 2001 From: Damien Dart Date: Wed, 24 Jan 2024 00:41:49 +0000 Subject: [PATCH] Move VirtualBox-related stuff to its own role. --- playbook-provision.yml | 1 + roles/development/defaults/main.yml | 1 - roles/development/tasks/main.yml | 3 -- roles/development/tasks/virtualbox.yml | 35 ------------------- roles/virtualbox/defaults/main.yml | 7 ++++ .../handlers/main.yml | 5 ++- roles/virtualbox/meta/main.yml | 6 ++++ roles/virtualbox/tasks/main.yml | 33 +++++++++++++++++ 8 files changed, 49 insertions(+), 42 deletions(-) delete mode 100644 roles/development/tasks/virtualbox.yml create mode 100644 roles/virtualbox/defaults/main.yml rename roles/{development => virtualbox}/handlers/main.yml (66%) create mode 100644 roles/virtualbox/meta/main.yml create mode 100644 roles/virtualbox/tasks/main.yml diff --git a/playbook-provision.yml b/playbook-provision.yml index c506243..b949d22 100644 --- a/playbook-provision.yml +++ b/playbook-provision.yml @@ -19,6 +19,7 @@ - 'rust' - 'syncthing' - 'tailscale' + - 'virtualbox' - 'webserver' vars: webserver__vhosts_cleanup: '{{ cli__website_cleanup | default(False) }}' diff --git a/roles/development/defaults/main.yml b/roles/development/defaults/main.yml index dfec72a..deeb0c4 100644 --- a/roles/development/defaults/main.yml +++ b/roles/development/defaults/main.yml @@ -66,7 +66,6 @@ development__obsidian_version: '1.4.16' development__projects_folder: 'Shed' development__run_gui_tasks: false development__update_dotfiles: false -development__virtualbox_version: '7.0' # The following variables will have host-specific and/or sensitive diff --git a/roles/development/tasks/main.yml b/roles/development/tasks/main.yml index 55d797d..6e04632 100644 --- a/roles/development/tasks/main.yml +++ b/roles/development/tasks/main.yml @@ -113,8 +113,5 @@ ansible.builtin.include_tasks: 'gui.yml' when: development__run_gui_tasks | bool -- name: 'Include VirtualBox installation tasks' - ansible.builtin.include_tasks: 'virtualbox.yml' - - name: 'Include Open VM Tools installation tasks' ansible.builtin.include_tasks: 'open-vm-tools.yml' diff --git a/roles/development/tasks/virtualbox.yml b/roles/development/tasks/virtualbox.yml deleted file mode 100644 index 0ffd7bf..0000000 --- a/roles/development/tasks/virtualbox.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Installs VirtualBox. -# -# This file was written by Damien Dart, . This is -# free and unencumbered software released into the public domain. For -# more information, please refer to the accompanying "UNLICENCE" file. - ---- -- name: 'Run VirtualBox-related tasks' - when: development__run_virtualbox_tasks | bool - block: - - name: 'Ensure the VirtualBox package signing key is present for APT' - ansible.builtin.apt_key: - state: 'present' - url: 'https://www.virtualbox.org/download/oracle_vbox_2016.asc' - - - name: 'Ensure the VirtualBox repository is present in APT sources list' - ansible.builtin.apt_repository: - repo: 'deb http://download.virtualbox.org/virtualbox/debian {{ ansible_distribution_release }} contrib' - state: 'present' - - - name: 'Ensure VirtualBox is installed' - ansible.builtin.apt: - force_apt_get: true - name: 'virtualbox-{{ development__virtualbox_version }}' - state: 'present' - - # To access USB devices from VirtualBox guests, the host user must - # be a member of the "vboxusers" group. For more information, see - # . - - name: 'Ensure administrator user has access to USB devices in VirtualBox' - ansible.builtin.user: - name: '{{ development__user_username }}' - groups: 'vboxusers' - append: true - notify: 'Notify user about "vboxusers" group membership update' diff --git a/roles/virtualbox/defaults/main.yml b/roles/virtualbox/defaults/main.yml new file mode 100644 index 0000000..c399cd2 --- /dev/null +++ b/roles/virtualbox/defaults/main.yml @@ -0,0 +1,7 @@ +# This file was written by Damien Dart, . This is +# free and unencumbered software released into the public domain. For +# more information, please refer to the accompanying "UNLICENCE" file. + +--- +virtualbox__vboxusers_users: [] +virtualbox__virtualbox_version: '7.0' diff --git a/roles/development/handlers/main.yml b/roles/virtualbox/handlers/main.yml similarity index 66% rename from roles/development/handlers/main.yml rename to roles/virtualbox/handlers/main.yml index 8d6a8e2..a94069b 100644 --- a/roles/development/handlers/main.yml +++ b/roles/virtualbox/handlers/main.yml @@ -6,6 +6,5 @@ - name: 'Notify user about "vboxusers" group membership update' ansible.builtin.debug: msg: >- - If the administrator user is currently logged in, you will need to - log out and log back in for the "vboxusers" group membership to - take effect. + If any users are currently logged in, you will need to log out and + log back in for the "vboxusers" group membership to take effect. diff --git a/roles/virtualbox/meta/main.yml b/roles/virtualbox/meta/main.yml new file mode 100644 index 0000000..69268e3 --- /dev/null +++ b/roles/virtualbox/meta/main.yml @@ -0,0 +1,6 @@ +# This file was written by Damien Dart, . This is +# free and unencumbered software released into the public domain. For +# more information, please refer to the accompanying "UNLICENCE" file. + +--- +dependencies: [] diff --git a/roles/virtualbox/tasks/main.yml b/roles/virtualbox/tasks/main.yml new file mode 100644 index 0000000..820a558 --- /dev/null +++ b/roles/virtualbox/tasks/main.yml @@ -0,0 +1,33 @@ +# Installs VirtualBox. +# +# This file was written by Damien Dart, . This is +# free and unencumbered software released into the public domain. For +# more information, please refer to the accompanying "UNLICENCE" file. + +--- +- name: 'Ensure the VirtualBox package signing key is present for APT' + ansible.builtin.apt_key: + state: 'present' + url: 'https://www.virtualbox.org/download/oracle_vbox_2016.asc' + +- name: 'Ensure the VirtualBox repository is present in APT sources list' + ansible.builtin.apt_repository: + repo: 'deb http://download.virtualbox.org/virtualbox/debian {{ ansible_distribution_release }} contrib' + state: 'present' + +- name: 'Ensure VirtualBox is installed' + ansible.builtin.apt: + force_apt_get: true + name: 'virtualbox-{{ virtualbox__virtualbox_version }}' + state: 'present' + +# To access USB devices from VirtualBox guests, the host user must +# be a member of the "vboxusers" group. For more information, see +# . +- name: 'Ensure specified users have access to USB devices in VirtualBox' + ansible.builtin.user: + name: '{{ item }}' + groups: 'vboxusers' + append: true + loop: '{{ [virtualbox__vboxusers_users] | flatten }}' + notify: 'Notify user about "vboxusers" group membership update'