My Six Part Blog Series provides a more exhaustive explaination of this project.
apt install python3-rich
# with pager
python3 -m rich.markdown README.md -p
# or without pager
python3 -m rich.markdown README.md
Build up a base template machine for Debian 11 Server. We will call it dnet.
virt-clone --original dnet --name dcon --auto-clone
The control machine will be for controlling everything.
It needs to have root ssh access to the base template machine (and then by extension all the clones), in order to configure the host names, host ssh keys, and reset the machine-ids.
Ansible does not need root ssh access.
- Install libnss-libvirt
apt install libnss-libvirt
- configure
/etc/nsswitch.conf
# /etc/nsswitch.conf
...
hosts: files libvirt dns mymachines
...
- build the virtual machines:
sudo bash build_vms.bash
- confirm that machines are running:
virsh list --state-running
- bring up the bridge networks:
bash define_bridge_networks.bash
virsh net-list
- shutdown the vms so you can connect them to the bridges:
bash shutdown_vms.bash
virsh list --state-running
- connect the vms to the bridges:
bash connect_vms_to_bridges.bash
virsh domiflist dnetone
virsh domiflist dnettwo
- etc
- restart the vms:
bash start_vms.bash
virsh list --state-running
- if necessary rebuild ssh known_hosts
bash rebuild_known_hosts.bash
virsh list --state-running
bash rebuild_known_hosts.bash
virsh list --state-running
- play with ansible
- shutdown the vms:
bash shutdown_vms.bash
virsh list --state-running
- disconnect vms from bridges:
bash disconnect_vms_from_bridges.bash
- undefine the vms:
bash undefine_and_remove_vms.bash
virsh list --all
- undefine the bridges:
bash remove_bridge_networks.bash
virsh net-list
# ~/.ansible.cfg
[defaults]
inventory = ~/router-lab/ansible/hosts.yml
# ~/.bashrc
export LIBVIRT_DEFAULT_URI="qemu+ssh://<user>@<host>/system"
alias ansible-pb=anspb
anspb() {
ANS_DIR=~/router-lab/ansible/playbooks;
echo Changing to "${ANS_DIR}" and executing: ansible-playbook "${@}"
(cd $ANS_DIR || exit ; ansible-playbook "${@}")
}
- configure the entire lab:
ansible-pb build_out_routers.yml -K