David Lundgren

Web Developer & Systems Administrator

Large file upload size issues

Lately I’ve been working on a project to help share my virtualbox vagrant’s privately. This is a very simple clone of the vagrant-cloud API that interacts with Packer & Vagrant. As part of this process, Packer uploads the artifacts it creates, and this became a problem in my dev environment. Between Nginx & Apache there are a few differences in how file uploads are configured, both defaults and in general.

Continue reading

Cleaning up Ansible task formatting

I’ve been using Ansible for the last several years, and I’ve used YAML just as long. Yet a lot of playbooks and tasks for Ansible are often horribly formatted. This causes anger within me, so I want to let others know, that there is a better way.

“Use the YAML, Ansible Writers”

YAML may not be as expressive as other formats, however, as authors of roles and tasks for Ansible we can do better at formatting so that they are readable.

Example of hard to read
[sourcecode language=”plain”]

– name: download file
get_url: url=https://raw.githubusercontent.com/some/path/some.file dest=/usr/local/share/some.file

– name: update permissions
file: path=/usr/local/share/some.file mode="0644"

Example of a more readable version of the above.

[sourcecode language=”plain”]

– name: download file
url: https://raw.githubusercontent.com/some/path/some.file
dest: /usr/local/share/some.file

– name: update permissions
path: /usr/local/share/some.file
mode: "0644"

It’s easier to change change /usr/local/share/some.file into "{{ download_file_dest }}" because you don’t have parse the entire line and scroll over in your HEAD!

BlockList.de IP lists with CIDR notation

Several weeks ago one of the servers I manage ended up with a lot of comment spam. After several hours of searching through the logs and correlating the IP’s, I found out that a majority of the hosts were listed in the BlockList.de’s bots.txt file. I didn’t want to import ALL the IP’s on the list as I noticed that quite a few could be pushed into fewer lines using CIDR notation.

I set out to compress this and ended up with this Gist that can do exactly that.

require_once "/path/to/BlocklistDe.php";

$botList = new BlocklistDe(‘bots.txt’);

This particular server was using Ubuntu, so I pushed the 13k addresses into the iptables configuration. Spam has been cut quite dramatically.

Creating a DHCP Server with vboxapi

While working on a project for work recently I stumbled across the need to create a network and associated DHCP server. The API documentation however only gave me the following reference to start the DHCP server.

void start (in wstring networkName, in wstring trunkName, in wstring trunkType)

trunkName and trunkType are not really documented in the IDHCPServer API page. Here are their documentation as I have discovered.

  • networkName: This is the IHostOnlyInterface.networkName property
  • trunkName: This should really be adapterName, as putting the IHostOnlyInterface.name property is correct
  • trunkType: This is one of the following TRUNKTYPE_* constants
    • These constants don’t exist in the VirtualBox_constants.py, but can be found in the NetworkServiceRunner.h
      • TRUNKTYPE_WHATEVER = ‘whatever’
      • TRUNKTYPE_NETFLT = ‘netflt’
      • TRUNKTYPE_NETADP = ‘netadp’
      • TRUNKTYPE_SRVNAT = ‘srvnat’

Putting this all together I ended up with code similar to the following

from vboxapi import VirtualBoxManager

# configuration
addresss = ‘’
netmask = ‘’
dhcp_from_ip = ‘’
dhcp_to_ip = ‘’

## Configure a HostOnly Interface and the associated DHCP Server
vbm = VirtualBoxManager(None, None)
vb = vbm.vbox

# create the network on the host
(progress, interface) = vb.host.createHostOnlyNetworkInterface()
interface.enableStaticIPConfig(address, netmask)

# create the dhcp server for this network
dhcpServer = vb.createDHCPServer(interface.networkName)
dhcpServer.setConfiguration(address, netmask, dhcp_from_ip, dhcp_to_ip)
dhcpServer.enabled = True
dhcpServer.start(interface.networkName, interface.name, ‘netadp’)

FreeBSD and sudo defaults

Several weeks ago I started transitioning some Ubuntu VM’s to FreeBSD VM’s . On previous VM’s I was able to use the following command line without any problems

sudo phing code-update

After switching to FreeBSD I found that sudo, or its “sudo -E” variant, was having problems when running in sub shells. Phing svn tasks were asking for passwords that were previously setup to use svn+ssh. Using “sudo svn list svn+ssh://svn.example.com/svn/project” worked but not when phing ran. It turns out there are two environment variables that Ubuntu’s sudo package was preserving: HOME & MAIL. NOTE: Ubuntu 14.04LTS’ sudo package appears to only preserve HOME.

I created /usr/local/etc/sudoers.d/svnusers

Defaults env_reset
Defaults env_keep+="HOME"

This made FreeBSD’s sudo work as it had on Ubuntu. A day’s worth of investigation to solve the riddle but it works as I would expect it to.