In my network I keep track of all static assigned IP addresses in my DHCP config. So I’ll connect a new device to my network and let DHCP give it a temp IP and arpwatch emails me its MAC address, then I decide what the perm address should be and add that to my DHCP config so the device reconnects at its new assigned IP.
But I prefer to configure servers with their static IP config so they’ll come up fine even if they come up faster than the DHCP server. So I’ll change the netplan to match the address the server already got from DHCP.
I saw solutions using a full template for the netplan config file but I decided to try the role by mrlesmithjr/ansible-netplan (GitHub - mrlesmithjr/ansible-netplan) and I’m pretty close but can’t figure out the last bit.
The last bit is that I’d like to use the ansible_default_ipv4.interface to fill in the interface device name, but couldn’t figure out how to build that into the above.
You could achieve that If you previously set a dict on a fact for your network config and then you pass the whole dict to the role, something like this:
I haven’t tested all the tasks since I didn’t wanted to install the role on my local machine, but I believe it should work. Debugging the my_network fact gives something like this:
You’re welcome Steve! Also glad that you can you use my answer to learn Ansible further, not only to get your issue sorted
PS: I forgot to mention before; on this scenario we could also use the combine() plugin filter, It comes really handy when modifying data on existing dictionaries.