diff --git a/Vagrantfile b/Vagrantfile index 0c2ca47..30a15c9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -50,6 +50,9 @@ Vagrant.configure('2') do |config| VirtualBox.guest_property(vb, HOST) end + # -- Disks --# + Host.disks(node.vm, HOST) + #-- Networking --# Host.networking(node.vm, HOST) diff --git a/docs/dev/ansible.md b/docs/dev/ansible.md index d6758fb..078bcdc 100644 --- a/docs/dev/ansible.md +++ b/docs/dev/ansible.md @@ -2,7 +2,7 @@ Ansible is an open-source [IaC](https://en.wikipedia.org/wiki/Infrastructure_as_code) tool, provides configuration management and application deployment. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. Ansible is **agentless**, temporarily connecting remotely via SSH (*distributed mode*) or Windows Remote Management (allowing remote PowerShell execution) to do its tasks on the [managed nodes](https://docs.ansible.com/ansible/latest/network/getting_started/basic_concepts.html). -Despite the default behaviour (connecting remotely), ansible supports an connection type known as **[local](https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html)** connection (*centralized mode*). In such case Ansible will execute any tasks on the [control node](https://docs.ansible.com/ansible/latest/network/getting_started/basic_concepts.html). Ansibe (control or managed) nodes are organized in an file known as the [inventory]() file. Sometimes called a *hostfile*. Your inventory can specify information like IP address, credentials and variables for each node. +Despite the default behaviour (connecting remotely), ansible supports an connection type known as **[local](https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html)** connection (*centralized mode*). In such case Ansible will execute any tasks on the [control node](https://docs.ansible.com/ansible/latest/network/getting_started/basic_concepts.html). Ansibe (control or managed) nodes are organized in an file known as the [inventory](https://docs.ansible.com/ansible/latest//user_guide/intro_inventory.html) file. Sometimes called a *hostfile*. Your inventory can specify information like IP address, credentials and variables for each node. !!! note Vagrant [ansible_local](../vagrant/provisioners.md) provisioner type uses the *local* connection and not the *remote* (SSH) to execute any guest machine tasks. In such case the guest machine is acting as a *control node*. diff --git a/docs/vagrant/disks.md b/docs/vagrant/disks.md new file mode 100644 index 0000000..00f7128 --- /dev/null +++ b/docs/vagrant/disks.md @@ -0,0 +1,79 @@ +# Overview + +Vagrant Disks is a feature that allows users to define what mediums should be attached to their guests, as well as allowing users to **resize** their primary disk. + +# Supported providers + +Currently, only **VirtualBox** is supported. Please refer to the [VirtualBox documentation](https://developer.hashicorp.com/vagrant/docs/disks/virtualbox) for more information on using disks with the VirtualBox provider! + +# Customizations + +This feature requires the following environmental flag to be used: + +```console +export VAGRANT_EXPERIMENTAL="disks" +``` + +!!! info "Reload Vagrant" + You will need to reload vagrant from the command line for resizing to take affect. + +Multiple disks can be added in the ``vagrant.yaml`` configuration file but only the disk with the ``:primary: true`` +option is what tells to vagrant to *expand* the guests main drive. Without this option, vagrant will instead attach a *new* +disk to the guest. + +```yaml +:host: + :disks: + - :type: 'disk' + :options: + :primary: true + :size: '80GB' + - :type: 'disk' + :options: + :size: '40GB +``` + +- If Vagrant is provisioned for the first time the [local ansible provisioner](../provisioners/#local-ansible-provisioner) will take care of
the logical volume and filesystem resizing. +- If Vagrant is **already provisioned** then you will need to execute: + +```console +vagrant provision --provision-with sandbox +``` + +or + +from inside the Vagrant box: + +```console +cd /shared/provisioners/ansible +ansible-playbook -i inventory.yml playbook.yml --tags resize_disk +``` + +Supported options are: + +- ``type``: The kind of the disk type, current accepts: + + - *disk* + - *dvd* + - *flopppy* + +- ``options``: + - ``primary``: Configures disk to be the *primary* disk t o manae on the guest. + - ``size``: The size of the disk to create. For example *10GB*. Not used for type *dvd*. + +# Limitations + +- Disks can only be **increased** in size. There is no facility to shrink a disk. +- Depending on the guest, you may need to resize the partition and the filesystem
from within the guest. +- Vagrant attaches all new disks defined to guests's primary controller. As of Virtualbox *6.1.x*
+ storage controllers have the following limits to the number of disks that are supported per guest: + + - IDE Controllers: 4 + - SATA Controllers: 30 + - SCSI Controllers: 16 + +# References + +- [vagrant-disks](https://developer.hashicorp.com/vagrant/docs/disks) +- [vagrant-disksize-plugin](https://github.com/sprotheroe/vagrant-disksize) +- [increasing-disk-space-vagrant-box](https://marcbrandner.com/blog/increasing-disk-space-of-a-linux-based-vagrant-box-on-provisioning/) diff --git a/docs/vagrant/provisioners.md b/docs/vagrant/provisioners.md index 62c7349..9f8adb8 100644 --- a/docs/vagrant/provisioners.md +++ b/docs/vagrant/provisioners.md @@ -233,8 +233,7 @@ Supported options are: - [awscli](https://pypi.org/project/awscli) - Universal command line environment for AWS. - ``:skip_tags:`` Only plays, roles and tasks that *do not match* these values will be executed. - - This parameter can be *string or list* of tags. - + - This parameter can be *string or list* of tag !!! info "More details on local ansible provisioner can be found at:" - [Ansible on Sandbox](../dev/ansible.md) - [Local Ansible Options](https://www.vagrantup.com/docs/provisioning/ansible_local) diff --git a/docs/vagrant/vagrantfile.md b/docs/vagrant/vagrantfile.md index 040a256..659151c 100644 --- a/docs/vagrant/vagrantfile.md +++ b/docs/vagrant/vagrantfile.md @@ -25,6 +25,7 @@ The most important configuration options are listed below: - ``config.vm.box_url`` - ``config.vm.customize`` - ``config.vm.define`` +- ``config.vm.disk`` - ``config.vm.forward_port`` - ``config.vm.guest`` - ``config.vm.hostname`` diff --git a/docs/vagrant/workflow.md b/docs/vagrant/workflow.md index be8e6d9..3fb0ac2 100644 --- a/docs/vagrant/workflow.md +++ b/docs/vagrant/workflow.md @@ -1,13 +1,13 @@ **Test and development** workflow using Vagrant includes: - Workspace - Host OS (*Windows or Linux*) -- A Base Box (*Guest OS*) -- A Git repository (*Vagrantfile, Test Automation framework source code*) -- Git/Git BASH -- [Chocolatey](../../chocolatey/guide/#what-is-chocolatey) package manager (**only for Windows OS**) -- Command Line Emulator such as [Cmder](../../cmder/guide/#what-is-cmder) (**only for Windows OS**) -- IDE (*Sublime, Atom*, etc) -- System Under Test +- The (Ubuntu) Base Box (*Guest OS*) +- Git repository (*Vagrantfile*) +- Git or Git BASH +- [Chocolatey](../../chocolatey/guide/#what-is-chocolatey) package manager (**Windows OS**) +- Command Line Emulator such as [Cmder](../../cmder/guide/#what-is-cmder) (**Windows OS**) +- IDE (*Sublime, Atom, VSCode*, etc) +- System Under Test (*optional*) Workflows: diff --git a/lib/vagrant-host.rb b/lib/vagrant-host.rb index 858877b..b0658ec 100644 --- a/lib/vagrant-host.rb +++ b/lib/vagrant-host.rb @@ -91,6 +91,22 @@ def ansible_provision(vm, host) vm.provision name, opts end + def disks(vm, host) + return unless host.key?(:disks) + + disks = host[:disks] + return unless disks.is_a?(Array) + + disks.each_with_index do |disk, index| + next unless disk.key?(:type) + + type = disk[:type].to_s.to_sym + opts = disk.fetch(:options, {}) + opts[:name] ||= "storage-#{index}" + vm.disk type, opts + end + end + def post_up_message(vm, host) return unless host.key?(:name) diff --git a/mkdocs.yml b/mkdocs.yml index 1d32aa3..535cc3c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -20,6 +20,7 @@ nav: - 'System': 'vagrant/system.md' - 'Provisioners': 'vagrant/provisioners.md' - 'Synced Folders': 'vagrant/shared.md' + - 'Disks': 'vagrant/disks.md' - 'Plugins': 'vagrant/plugins.md' - 'Debugging': 'vagrant/debugging.md' - 'Workflow': 'vagrant/workflow.md' diff --git a/provisioners/ansible/playbook.yml b/provisioners/ansible/playbook.yml index 09c8010..8304c76 100644 --- a/provisioners/ansible/playbook.yml +++ b/provisioners/ansible/playbook.yml @@ -9,8 +9,9 @@ name: 'common/system' tags: 'always' roles: - - { role: 'system/bash_aliases', tags: 'bash_aliases' } - - { role: 'system/bash_profile', tags: 'bash_profile' } + - { role: 'system/bash/aliases', tags: 'bash_aliases' } + - { role: 'system/bash/profile', tags: 'bash_profile' } + - { role: 'system/disks', tags: 'resize_disk' } - { role: 'python/ipython', tags: 'ipython' } - { role: 'python/tox', tags: 'tox' } - { role: 'docker', tags: 'docker' } diff --git a/provisioners/ansible/roles/repos/defaults/main.yml b/provisioners/ansible/roles/repos/defaults/main.yml index 34743a1..d83f3df 100644 --- a/provisioners/ansible/roles/repos/defaults/main.yml +++ b/provisioners/ansible/roles/repos/defaults/main.yml @@ -1,15 +1,9 @@ --- -repositories: - - name: 'vagrantenv' - src: 'git@github.com:theodore86/vagrantenv.git' - dest: '{{ ansible_env.HOME }}' - version: 'main' - pull: true - remote: 'origin' - - name: 'sublime' - src: 'git@github.com:theodore86/sublime.git' - dest: '{{ ansible_env.HOME }}' - version: 'master' - pull: true - remote: 'origin' +# - name: 'vagrantenv' +# src: 'git@github.com:theodore86/vagrantenv.git' +# dest: '{{ ansible_env.HOME }}' +# version: 'main' +# pull: true +# remote: 'origin' +repositories: [] ... diff --git a/provisioners/ansible/roles/system/bash_aliases/defaults/main.yml b/provisioners/ansible/roles/system/bash/aliases/defaults/main.yml similarity index 100% rename from provisioners/ansible/roles/system/bash_aliases/defaults/main.yml rename to provisioners/ansible/roles/system/bash/aliases/defaults/main.yml diff --git a/provisioners/ansible/roles/system/bash_aliases/tasks/main.yml b/provisioners/ansible/roles/system/bash/aliases/tasks/main.yml similarity index 100% rename from provisioners/ansible/roles/system/bash_aliases/tasks/main.yml rename to provisioners/ansible/roles/system/bash/aliases/tasks/main.yml diff --git a/provisioners/ansible/roles/system/bash_profile/defaults/main.yml b/provisioners/ansible/roles/system/bash/profile/defaults/main.yml similarity index 100% rename from provisioners/ansible/roles/system/bash_profile/defaults/main.yml rename to provisioners/ansible/roles/system/bash/profile/defaults/main.yml diff --git a/provisioners/ansible/roles/system/bash_profile/tasks/main.yml b/provisioners/ansible/roles/system/bash/profile/tasks/main.yml similarity index 100% rename from provisioners/ansible/roles/system/bash_profile/tasks/main.yml rename to provisioners/ansible/roles/system/bash/profile/tasks/main.yml diff --git a/provisioners/ansible/roles/system/disks/defaults/main.yml b/provisioners/ansible/roles/system/disks/defaults/main.yml new file mode 100644 index 0000000..53c69bf --- /dev/null +++ b/provisioners/ansible/roles/system/disks/defaults/main.yml @@ -0,0 +1,7 @@ +--- +disks_dependencies: + - 'lvm2' +disks_pvs: '/dev/sda3' +disks_vg_name: 'ubuntu-vg' +disks_lv_name: 'ubuntu-lv' +... diff --git a/provisioners/ansible/roles/system/disks/tasks/main.yml b/provisioners/ansible/roles/system/disks/tasks/main.yml new file mode 100644 index 0000000..f53ea9f --- /dev/null +++ b/provisioners/ansible/roles/system/disks/tasks/main.yml @@ -0,0 +1,28 @@ +--- +- name: 'Install disks dependencies' + apt: + name: '{{ disks_dependencies }}' + state: 'present' + force_apt_get: 'yes' + install_recommends: 'no' + become: 'yes' + +- name: 'Resize volume-group {{ disks_pvs }} to the maximum possible' + lvg: + vg: '{{ disks_vg_name }}' + pvs: '{{ disks_pvs }}' + pvresize: 'yes' + state: 'present' + become: 'yes' + +- name: > + Extend the logical volume to take all remaining space + of the PVs and resize the underlying filesystem. + lvol: + vg: '{{ disks_vg_name }}' + lv: '{{ disks_lv_name }}' + size: '100%PVS' + resizefs: 'yes' + state: 'present' + become: 'yes' +... diff --git a/vagrant.yaml b/vagrant.yaml index 8949bd0..b89ac2b 100644 --- a/vagrant.yaml +++ b/vagrant.yaml @@ -36,6 +36,11 @@ :memory: null :boot_timeout: 60 :gui: false + :disks: + - :type: 'disk' + :options: + :primary: true + :size: '80GB' :customize: - :command: 'modifyvm' :settings: @@ -161,6 +166,5 @@ :extra_vars: :gitconfig_user_name: 'Theodoros Georgomanolis' :gitconfig_user_email: 'tgeorgomanolis@gmail.com' - :skip_tags: - - 'repos' + :skip_tags: [] ...