Output of Vagrant and libvirt on Fedora 40

Vagrant and libvirt on Fedora 40

I recently purchased a copy of DevOps for the Desperate by Bradley Smith from No Starch Press. In the first chapter, it explains how to use Vagrant to create easily re-deployable VMs for use with the exercises. The examples use VirtualBox for running the VMs. Normally this wouldn’t be much of an issue but, at the time of writing, there are no VirtualBox RPMs available for the newly released Fedora 40.

After some Googling, I found that there is a libvirt plug-in for Vagrant that can be used instead of the default VirtualBox provider.

The steps below explain how I configured my system to use Vagrant and libvirt on Fedora 40. This allowed me to follow along with the book from the “Getting Started with Ansible” section.

Installation and Configuration

Everything needed can be installed using 2 Fedora package collections. @virtualization which will enable us to run VMs and @vagrant which installs Vagrant and the libvirt provider for Vagrant.

dnf install @virtualization @vagrant

Next, start and enable a couple of the virtualization daemons:

systemctl enable --now virtqemud.service
systemctl enable --now virtnetworkd.service

You will then need to add your user to the libvirt group.

usermod -aG libvirt $USER

Once added to the group, you will need to log out and back in for the group membership changes to take effect. On Fedora 40 GNOME, I found that logging out and back in using the UI option didn’t update my group membership. The following command will force a full logout for the current user session:

loginctl terminate-user $USER

Then, once logged back in, your membership of the libvirt group should be listed when running the following command:

groups

Alternately, if you don’t want to logout for whatever reason, you could also just run:

su - $USER

which will start a new shell environment with updated group membership.

At this point all the installation and configuration is complete.

However, some small changes are needed to the Vagrant file that the book uses. This is to account for us using the libvirt provider rather than virtualbox provider. Below is what my Vagrant file now looks like (with all the comments removed):

The Vagrant File

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2004"
  config.vm.hostname = "dftd"

  config.vm.provider "libvirt" do |libvirt|
    libvirt.memory = "1024"
  end

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "../ansible/site.yml"
    ansible.compatibility_mode = "2.0"
  end
end

Note that config.vm.box has been changed to “generic/ubuntu2004” as “ubuntu/focal64” does not support libvirt. I also removed a line from the Vagrant file relating to “config.vm.network”. By running:

sudo virsh net-list --all

I found that libvirt includes a default network which already had the settings I wanted. By deleting the config.vm.network line from the Vagrant file, it uses the default libvirt network settings.

Finishing Up

Now when I run “vagrant up” it successfully starts the VM and I can follow along with the next part of the book:

Output of Vagrant and libvirt on Fedora 40

Vagrant and libvirt on Fedora 40.

Plotting Circles in PICO-8

Click on the image below to start the program and see the excitement of trigonometry in action! Plotting circles in PICO-8.

Introduction

Recently I have been playing around with PICO-8. It’s a “fantasy console” that hearkens back to the NES days and includes a fully integrated development environment. This makes it a really convenient tool for learning game development or even just some graphics programming.

For this example, I wanted to learn how to program an object that orbits some origin point. In the context of game development, maybe it could be a shield or some kind of particle effect that orbits around the player’s position.

To do this, I had to learn about plotting circles in PICO-8. To my surprise, the math required is fairly minimal!

The math

You need the X and Y co-ordinate of an origin point, the radius (or distance you’d like the outer point to orbit at) and the angle of the point to plot in relation to the origin.

origin_x = 64
origin_y = 64
radius   = 10
angle    = 0

x = origin_x + radius * cos(angle/360)
y = origin_y + radius * sin(angle/360)

Using the math above, the first set of X and Y values returned would be (74,24). If we were to increment the angle by 5, the next result would be (74,62) when rounded.

Throw this into a loop that increments the angle each update, then plots the new point and job done!

Example program code

The below code is all you need to create a working example in PICO-8. PICO-8 calls the _UPDATE() function 30 times a second and the _DRAW() function 15, 30 or 60 times a second.

origin_x = 64
origin_y = 64
radius   = 10
angle    = 0
inc      = 5
x,y      = 0,0

function _update()
 angle += inc
 
 if (angle > 360) angle -= 360 //Keeps the angle between 0 and 360
 
 x = origin_x + radius * cos(angle/360)
 y = origin_y + radius * sin(angle/360)
end

function _draw()
 cls() //Clear the screen
 circfill(origin_x, origin_y, 3, 7) //Draw the inner circle
 circfill(x, y, 1, 7) //Draw the orbiting circle
end

What next?

My example program that I’ve embedded at the very start of this post is just an expanded version of the above code. I added in some controls for increasing and decreasing the radius, increasing and decreasing the angle increment (speed at which it moves) and holding the X key will pause it. Then I just plotted a few extra lines to help visualise the movement of the X and Y values.

I’m hoping to use this new knowledge to build some PICO-8 games with more interesting movement paths. I’m currently working on a Space Invaders style of game as a learning project and using similar math to enable enemies to move in more interesting patterns, as oppose to just moving straight down the screen.

Starting to wish I paid more attention in high school trigonometry classes!

Identify Locked AD Users via PowerShell

If you manage your Active Directory using only the ADUC GUI, it’s not particularly easy to identify all locked user accounts at once. Whilst you can do this by using queries within ADUC, I find it much more convenient to use PowerShell. In this short guide I will show you how to identify locked AD users via PowerShell.

The PowerShell cmdlets used in this post are from the ActiveDirectory module. This should already be installed on your Domain Controller, but can also be installed locally as part of Remote Server Administration Tools (RSAT).

If you have dabbled with the ActiveDirectory module before, your first instinct might be to use the Get-ADUser cmdlet to return all users and then filter the output to show only those with a LockedOut property equal to true.

Output of trying to identify Locked AD Users via PowerShell using Get-ADUser

As shown in the screenshot above, this approach doesn’t work. It produces an error message directing you to the Search-ADAccount cmdlet instead.

Running the Search-ADAccount cmdlet with the -LockedOut flag will return a list of all accounts that are currently locked. You can then pipe the output to the select cmdlet (an alias for Select-Object) to only include useful information.

Identifying Locked AD Users via PowerShell using Search-ADAccount

As shown in the redacted screenshot above, you can output the user’s name, samAccountName and PasswordExpired properties to get a more easily manageable overview. The PasswordExpired property can be useful if you are troubleshooting account lockouts.

If at this point you want to unlock one or more of the accounts, PowerShell can come to the rescue again! There is an Unlock-ADUser command which, when given a username (or list of them), will unlock the account from the command line.

So, in summary, if you want a quick list of all the currently locked out AD users, run the following:

Search-ADAccount -LockedOut | select -Property name, samAccountName, PasswordExpired

If you found that user “dean” was locked out, you could unlock the account with the following command:

Unlock-ADAccount dean

Hopefully this guide offers a quick insight into the power of PowerShell. It’s an incredibly useful tool that all Windows admins can benefit from.

Mastodon