I changed the order so hostname is set before the /etc/hosts file is modified. This prevents a problem on amazon where the hostname is incorrect and is added to the hosts file