host module issues/thoughts

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.

I coming back to this to a more constructive way:

I created a gist how I see this module should work.

Currently host module does not expect there can be more than once identical hostname (can be identical for ipv4 and ipv6) and it only handles first found one, which can result of some weird ipv6 to ipv4 changes…

Anyway. not a big problem:

Here is the gist: https://gist.github.com/resmo/7542680

The biggest change is, that you can define a hostname=example state=absent and it will remove ipv4 and ipv6 records.

Thanks for review and feedback.

We’ve already talked about this quite a bit.

The module should treat the name as a primary key, the aliases right now are values. This is good.

Right now, it sets the values to the primary key to what you want the to be.

There should also be an “append” mode to add values keeping existing values, so you don’t have to explicitly set them.

But it’s non-intuitive to set an alias to absent, or an alias value to present.

We’ve looked at this a little closer and there needs to be a bit of more thought around the alias handling.

We’re going to drop this new module out of tree for now, and come up with a spec for how it should work, and then we’ll accept something coded to that spec.

This could be based on the existing patch to preserve attribution but I’m not quite ok with some of the automagic.