Ansible exists to help automate the time consuming repeated tasks that technologist depend upon. One very common jobs is to create and tear down a virtual machine. While cloud technologies have made this possible to perform remotely, there are many times when I’ve needed to setup and tear down virtual machines on systems that were stand alone Linux servers. In this case, the main interfaces to the machine are ssh and libvirt. I recently worked through an Ansible role to setup and tear down an virtual machine via libvirt, and I’d like to walk through it, and record my reasons for some of the decisions I made.
The Workstation on top of my server rack has 3 Ethernet ports. One is built in to the mother board, and and two are on a card. I want to use these three ports for different purposes. How can I tell which is which internally? The answer lies in /sys/bus/pci/devices/.
I do this infrequently enough that I want to record a reminder how I do it:
sudo cp ~/Downloads/rhel-server-7.6-x86_64-kvm.qcow2 /var/lib/libvirt/images/tower.qcow2 sudo virt-install --vcpus=2 --name tower --ram 4096 --import --disk /var/lib/libvirt/images/tower.qcow2
Not all of my virtual machines run on OpenStack; I have to run a fair number of virtual machines on my personal workstation via libvirt. However, I like using the cloud versions of RHEL, as they most closely match what I do run in OpenStack. The disconnect is that the Cloud images are designed to accept cloud-init, which pulls the ssh public keys from a metadata web server. Without that, there are no public keys added to the cloud-user account, and the VM is unaccessable. Here is how I add the ssh keys manually.
Now that we can use the REST API to list inventory, it is not a big stretch to decide we want to kick off Jobs, too. Here it is in a nutshell, and some related operations for working with jobs and templates.
In an earlier post, I wrote about using the OpenStack Ansible inventory helper when calling and Ansible command line tools. However, When developing an playbook, often there is more information pulled from the inventory than just the set of hosts. Often, the inventory also collects variables that are used in common across multiple playbooks. For this reason, and many more, I want to be able to call an Ansible playbook or Ad-Hoc command from the command line, but use the inventory as defined by an Ansible Tower instance. It turns out this is fairly simple to do, using the REST API.
While Tower makes it easy to manage custom inventory, I still want to develop using the command line. Thus, I want to generate a comparable smart inventory for my Ansible playbook as I get from tower.
I’ve been building a home cluster for investigative work. Here’s what I have so far.
Reading draws me in. While this has done me much good in my life, it also means that I can easily get sucked into reading a news site, and waste too much time. It took me a long time to figure out how to effectively block sites that I want to browse occasionally.