Ubuntu 18.04 Templates - Duplicate IPs

less than 1 minute read

Oh, the joy of Ubuntu 18.04 continually amazes me. As long as I have been using it, I have not provisioned mass VMs using a template. I use Packer for all of my image building of course, but I only do development using Vagrant for the most part. So, this has not been an issue so far. The issue I experienced has been well documented, but I wanted to put this here for my own reference. Upon spinning up multiple VMs, and then attempting to provision them with Ansible, I started getting errors back from Ansible about issues with the SSH keys. Upon further investigation, I found that all Ubuntu 18.04 VMs all had the same IP address assigned from DHCP. WTF! After searching around, I found that the culprit was coming from the same id being assinged in /etc/machine-id. So, the solution is actually quite simple, and can be resolved as part of the image building process. Simply execute the following during your provisioning:

# Fix machine-id issue with duplicate IP addresses being assigned
if [ -f /etc/machine-id ]; then
    sudo truncate -s 0 /etc/machine-id
fi

Once you have done that, you are good to go!

Enjoy!

Leave a comment