I'm trying to standup a Ubuntu 20.04 based AMI with 2 NICs connected to 2 different subnets and have those NICs configured automatically. I've read the guidance about creating file in /etc/netplan to define the NIC interface but have been reading through cloud-init python scripts, since EC2 is using it to init the NICs, to figure out why this isn't done automatically and I think I found the root cause ... it seems cloud-init starts out properly configuring both NICs but then deletes the config for the primary NIC meaning that in order to SSH I would need to go over the secondary NIC. I managed to get cloud-init to initialize both NICs correctly by editing the following file and commenting out the following lines of code
/usr/lib/python3/dist-packages/cloudinit/net/__init__.py
def _bringup_device(self):
....
#self.cleanup_cmds.append(
# ['ip', '-family', 'inet', 'link', 'set', 'dev', self.interface,
# 'down'])
#self.cleanup_cmds.append(
# ['ip', '-family', 'inet', 'addr', 'del', cidr, 'dev',
# self.interface])
def _bringup_router(self):
...
#self.cleanup_cmds.insert(
# 0,
# ['ip', '-4', 'route', 'del', self.router, 'dev', self.interface,
# 'src', self.ip])
....
#self.cleanup_cmds.insert(
# 0, ['ip', '-4', 'route', 'del', 'default', 'dev', self.interface])
To confirm that the solution works I delete all the cloud-init collateral and reboot to force it to restart. I also created a new custom AMI from the EC2 instance after deleting the files and confirmed that a new EC2 comes up with both NICs properly configured too
rm -rf /var/lib/cloud/*
Having to modify + maintain a custom copy of cloud-init is probably not a sustainable long term solution ... would this be a cloud-init issue or an EC2 cloud-init config issue? What's the best course of action to have this as an available long term solution? I think having cloud-init handle the NIC initialization vs. having to hand craft a file in /etc/netplan/ is probably a more sustainable long term solution.
Thanks