Make sure prerequisites are installed:
- Git - https://git-scm.com/downloads
- VirtualBox - https://www.virtualbox.org/wiki/Downloads
- Vagrant - https://www.vagrantup.com/downloads
In order to share code and fork the repository a Github account is needed. In case you don't have that yet, it's a good opportunity to create one ;)
In order to save time during the workshop (requires download of ~1.5GB image file) or have a chance to troubleshoot any installation issues before the workshop, please run the following commands upfront:
$ git clone https://github.com/Zuehlke/linux-developer-vm-with-ansible
$ cd linux-developer-vm-with-ansible
$ vagrant up --no-provision
$ vagrant destroy -f
In case there are any issues with the above commands, please let me know!
Goal: Getting the Developer VM up and running
- just run
vagrant up:)
While this is running in the background (might take a few minutes), please continue with lab 2.
Goal: Get familiarized with the structure of the template project
- review the existing Ansible in the
roles/directory - review the corresponding Testinfra tests in the
spec/directory - review the output from running
vagrant upin lab 1 - check the README file on the VM Desktop (and configure your keyboard layout)
Goal: Adapt the Dev-VM name in the README + Vagrantfile and switch to your Git repository
- adapt the
README.mdto describe your VM - adapt the VM name in
Vagrantfile - create a new repo under your Github account (or alternatively fork the template repo)
- switch the origin to point to your repo, then commit your changes and push
- run
vagrant reloadto have the VM name changed in VirtualBox as well
Example:
$ git remote set-url origin https://github.com/tknerr/zdecamp21-developer-vm.git
$ git commit -am "Adapt for ZCamp21 Developer VM"
$ git push origin master
Goal: Learn how to take VM snapshots as a rescue point
- run
vagrant snapshot save startto create a snapshot of the current VM state - do some changes in the VM, e.g.
sudo apt install sl(yes... I know you want to tryslnow... ;)) - revert to previous state
vagrant snapshot restore start(you can do that any time you borked your system and want to start back over)
Goal: Write your first Ansible task and Testinfra spec
Let's start TDD-style by writing a failing test first:
- create a new test spec
spec/test_cowsay.py - use the Testinfra package module to check that the "cowsay" package is installed
- run
vagrant provisionto verify that we have a failing test now
Then create a new Ansible role to install the "cowsay" package:
- create a new Ansible role named "cowsay" under the
roles/directory - use the Ansible (apt module)[https://docs.ansible.com/ansible/2.9/modules/apt_module.html] to install the cowsay package
- make sure the newly added cowsay role is referenced in
site.yml, so that Ansible will pick it up - run
vagrant provisionto trigger the provisioning and review the Ansible output - in the VM, run
cowsay hello(alternatively, runvagrant ssh -c "cowsay hello"on your host)
Additional hints:
- take a look at the other test specs (e.g.
test_git.py) for inspiration on further checks you coud add to ensure a proper installation of cowsay - you can run
UPDATE_VM_FLAGS=--verify-only vagrant provisionto skip the Ansible provisioning and run only the tests - you can run
ROLE_TAGS=cowsay vagrant provisionto run Ansible provisioning only for the "cowsay" role (but ignore all others) - you can disable the cows in the Ansible output by setting the
ANSIBLE_NOCOWS=1env var via the~/.bashrc.dmechanism provided by the bashrc_d role
Goal: Understand how to export the VM as an .ova image so that it can be distributed to the team
- follow the instructions in the "Packaging" section to export the .ova image
Goal: Run through the VM import process so that you can work from within the imported VM now
- follow the instructions in the "Usage" section
- import the .ova image
- verify that everything works by running the
update-vmcommands - review the
~/vm-setupdirectory and it's connection toupdate-vm
Notes:
- this is the point where you should consider sharing the VM .ova image with your team!
- at this point you do not need Vagrant anymore and can extend the toolchain from within the VM!
- you need to switch back to Vagrant everytime you want to create a fresh .ova image (and consider having a CI process that regularly builds these .ova images via vagrant)
Workshop ends here, this is left for you... :)