See this thread on github for the backstory: https://github.com/ansible/ansible/issues/4926
The short version is: under some circumstances, the module will make more changes than [I] expected to the /etc/hosts file. Some of this is a broken default file from a provisioner, and some of this is undefined module functionality.
So after some thinking about this, I would propose that by default, the host module should only dpi what I ask of it:
ip=192.168.3.10 hostname=vagrant-chef-server state=present
For this command, simply ensure that a line with that ip exists with that hostname in /etc/hosts. Nothing more. Nothing less.
If that ip exists with another name, change the name. If no line with that ip exists, add it. But it should NOT attempt to remove that name from any other line in the file, or at that time, manage the resolvability of the entire file but munging other records (i.e. “moving” the name from one line to another). I’m asking for line maintainers, not entire file management, imho.
If I want to remove that name from another line, I say it’s up to me to call the host module again to configure that line.
Now of course, that’s the least surprise functionality. We could then add a unique_hostname=yes/no and keep_aliases=yes/no to tell it that it should a) try to remove the name from other lines if it exists on another ip (in primary or aliases) and also when removed, to delete the line, or leave any existing aliases in place after removing that name.