Issue #1240: Improved handling of /etc/hosts updates by ensure_hostname_in_hosts

Assuming that ```ensure_hostname_in_hosts``` should be altering ```/etc/hosts```, here are some proposed changes.