Configuration management that runs over SSH, namely Ansible, benefits in having test machines available on the network. The enclosed Vagrantfiles provide multiple virtual machines to run as guests on the developer's machine. The guests appear as hosts on the LAN, providing a local ephemeral cloud.
The virtual machines here are similar, but different. One provides Ubuntu 14.04 LTS ("trusty"), another provides Ubuntu 18.04 LTS ("bionic"), and another provides CentOS Linux 8 ("centos8"). Together they provide a test environment for the basis of an inventory to test configuration on machines old and new.
More broadly, these Vagrantfiles demonstrate how to get multiple virtual
machines on your LAN for testing from your development machine with
vagrant. A simple diff
of any two Vagrantfiles suggests how you
might template the configuration for larger projects, given enough RAM.
The shell provision in the Vagrantfile provides the starting point as the preexisting state of the virtual machine before configuration management picks up.
Run each Vagrantfile (see Usage below) then connect to throwaway virtual machines on your network.
These Vagrantfiles assist in experimenting with configuration and specific scenarios. To test infrastructure, see Kitchen.
- Configure each host with 2 CPUs and 1GB RAM.
- Disable vagrant's default bind/synced folder at
/vagrant
. - Provision with inline shell to set the initial state.
- Connect to the public network.
- Append all developer authorized_keys to vagrant SSH.
A Vagrantfile assumes that the machine running vagrant has enough CPUs and RAM to create the virtual machine.
- Add the ID of your machine's network interface to each Vagrantfile. (See the comment "To display valid options..." in the Vagrantfile.)
- Set one Vagrantfile per directory; run
vagrant
in each directory. - Bring hosts up with
vagrant up && vagrant reload
. - Stop hosts with
vagrant halt
. - Delete hosts with
vagrant destroy
.
Vagrantfiles for testing only. Run only on trusted networks.
Before you git add .
... These Vagrantfiles are mostly portable, but in
configuring the network bridge, they include details about the local developer
machine (including use of VirtualBox, which is a developer preference).
Therefore, these Vagrantfiles cannot be shared across developer machines and
therefore should not be checked into version control as-is without additional
consideration.
Install VirtualBox and vagrant.
Put each Vagrantfile into its own directory:
mkdir -p bionic trusty centos8
mv Vagrantfile.bionic ./bionic/Vagrantfile
mv Vagrantfile.trusty ./trusty/Vagrantfile
mv Vagrantfile.centos8 ./centos8/Vagrantfile
Update each Vagrantfile with the identifier of your network interface. See the comment "To display valid options..." in the Vagrantfile.
Is your LAN configured for DHCP... will the router accept any new host? If so,
keep the dhcp
configuration already in place. If not, review the public
networks documentation and consider setting ip: "192.168.1.99"
using whatever static IP value is appropriate.
Maintain a unique, fake MAC address for each Vagrantfile. This is already done in the Vagrantfiles provided, but note that you should adjust the last 6 characters of each mac to a unique value when forking Vagrantfile configurations.
Bring up each host:
cd ./bionic
vagrant up && vagrant reload
cd ./trusty
vagrant up && vagrant reload
cd ./centos8
vagrant up && vagrant reload
You can run these in parallel, but if you changed the Vagrantfile to use the
same config.vm.box
to make two run the same Ubuntu version, then let vagrant
complete one host before starting the other. If there are any errors, review
the log output carefully, as the issue is likely with your particular vagrant
configuration or the underlying VirtualBox installation.
When you are ready to stop hosts, run vagrant halt
in the directory of each
Vagrantfile. Run vagrant destroy
to delete the virtual machine.
Making changes to the shell provision in the Vagrantfile? With the host running, run:
vagrant provision
Connect to each host:
ssh vagrant@<resulting_bionic_ip>
ssh vagrant@<resulting_trusty_ip>
ssh vagrant@<resulting_centos8_ip>
If your network resolves hostnames on the LAN:
ssh vagrant@bionic
ssh vagrant@trusty
ssh vagrant@centos8
Helpful configuration for ~/.ssh/config
:
Host bionic
User vagrant
StrictHostKeyChecking no
Host trusty
User vagrant
StrictHostKeyChecking no
Host centos8
User vagrant
StrictHostKeyChecking no
This allows a more direct ssh invocation and appreciates that vagrant will
change host sshd keys on each newly created vagrant up
virtual machine.
ssh bionic
ssh trusty
ssh centos8
Now you have hosts on the LAN, accessible by SSH, for testing configuration management.
--@rduplain