When upgrading from a /etc/hosts file created before commit
ae02667b84 the old entries were not
removed on the first run. The hostname generation had to be run again to
remove them.
Reordering the if statement ensures that existing entries are changed
instead of adding new entries for the same IP address and that
duplicate entries are removed in all cases.
Change-Id: I2a21d13310b457e91a090541ae7f02f974413965