Thursday, November 28, 2024

Adding Space to an Ubuntu VM

I ran out of space on an Ubuntu VM today and had to go through the process of expanding the hard drive. 

  1. First, we shut down the VM and reconfigured VMware to let it have a larger hard drive. 
  2. Another thing to note is that we used the default settings when configuring the disk when installing Ubuntu.
  3. We downloaded the ISO for GParted. This is an entirely self contained OS with Gparted installed (along with a few other tools) and mounted it in the optical drive of the VM and booted it up.
  4. When it finished booting, we used GParted to expand the partition to use the extra space on the drive.
  5. Then we ejected the ISO and booted up as normal.
  6. Since we used the default options when installing Ubuntu, it uses a logical volume. We expanded the logical volume to encompass the new expanded size of the partition on the physical (virtual) drive using this:
    sudo lvextend -l 100%VG ubuntu-vg-/ubuntu-lv
  7. Then we increased the size of the file system to use the available space in the logical volume using this:
    sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
A simple df -h later and we could see that the drive now had access to the extended space.

Thursday, November 21, 2024

Freeing up Disk Space when using Docker

 Turns out there's a lot of temporary data that is used by Docker. To clean it up, try the following (courtesy Mr Davron):

  1. Open an elevated Powershell or CMD prompt
  2. `docker system prune --all`
  3. Right mouse click on docker desktop in system tray -> quit
  4. `wsl --shutdown`
  5. `Optimize-VHD -Path "$env:LOCALAPPDATA\Docker\wsl\data\ext4.vhdx" -Mode Full`
  6. Reboot
This freed up about 25GB on my machine.

Thursday, November 14, 2024

Using Ansible in Docker (without installing Ansible)

tl;dr:

Powershell:

docker run --rm -v ${PWD}:/ansible/playbooks sweenig/ansible-docker playbook.yml -i inventory

Linux:

docker run --rm -v $(pwd):/ansible/playbooks sweenig/ansible-docker playbook.yml -i inventory

I love Ansible. I love Docker. Running Ansible in Docker not only makes me melt but it means I don't have to install anything but Docker to run Ansible. Anywhere Docker works, Ansible works. And since I already have Docker installed on any machine I call mine...

I built a lab that shows how this can be used. The lab spins up 4 Ubuntu servers, then uses Ansible in a docker container to install a few things. Here's the shortcut to get everything up and running if you already have Docker installed:

> docker run -it --rm -v ${HOME}:/root -v ${PWD}:/git alpine/git clone https://github.com/sweenig/docker-ansible-playbook.git
cd .\docker-ansible-playbook\ansible_lab\
> docker compose up -d
> docker run --rm -v ${PWD}:/ansible/playbooks --network=ansible_lab_default sweenig/ansible-docker playbook.yml -i inventory

With these four commands, you:

  • Pull down the lab files
  • Switch into the lab directory
  • Start up 4 containers (the equivalent of starting up 4 micro VMs)
  • Run the Ansible playbook
You used Git and Ansible and had neither installed.

To shut down the lab, do:
docker compose down
In the ansible-lab directory.

Thursday, November 7, 2024

Using Git without Installing it (through Docker)

If you follow this blog, you might already know that I'm a Docker fanboy. Docker containers are like micro-VMs, just lighter and faster. Git is version control software. The nice thing about version control software, or more specifically distributed version control software like Git, is that it not only allows for the storage of blobs of text or bytes but it also allows you to build workflows that enable people to contribute edits to the stored text along with approval and multiple branches.

Installing Git isn't always needed. Sometimes I just need to clone a repo. If I have Docker installed, I do this (in Powershell):

docker run -it --rm -v ${HOME}:/root -v ${PWD}:/git alpine/git clone https://github.com/sweenig/docker-ansible-playbook.git

Linux/Mac is just as easy:

docker run -it --rm -v ${HOME}:/root -v $(pwd):/git alpine/git clone https://github.com/sweenig/docker-ansible-playbook.git

If you want, you can even setup an alias in Bash:

Linux:
alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"

Or in Windows with Powershell:
function git {
  $allArgs = $PsBoundParameters.values + $args
  docker run --rm -it -v ${PWD}:/git -v ${HOME}:/root alpine/git $allArgs
}
With Powershell, since the underlying container is running Linux, make sure that the path to the playbook and inventory files doesn't use the backslash.