While it isn't common dpkg -l should be safe as it is "essential: Yes".
The line you added isn't super complex and should get the issue of the lingering file solved.
The only thing I'm wondering is - would at this stage the first entry of dpkg -l being "Desired state" already be "i" for motd-news-config itself.
If it isn't then keep things as-is and at least I'm +1 on it.
But if it is "i" then checking directly for motd-news-config ready more logically and would cover any awkward dependency messing that prevents it from being installed despite ubuntu-server being present (none come to mind right now, but you know to be on the safe side).
While it isn't common dpkg -l should be safe as it is "essential: Yes".
The line you added isn't super complex and should get the issue of the lingering file solved.
The only thing I'm wondering is - would at this stage the first entry of dpkg -l being "Desired state" already be "i" for motd-news-config itself.
If it isn't then keep things as-is and at least I'm +1 on it.
But if it is "i" then checking directly for motd-news-config ready more logically and would cover any awkward dependency messing that prevents it from being installed despite ubuntu-server being present (none come to mind right now, but you know to be on the safe side).