salt icon indicating copy to clipboard operation
salt copied to clipboard

state/host.present and alias-assignment to multiple IPs fails

Open rmatulat opened this issue 11 years ago • 5 comments

What we try to do:

Assign localhost to 127.0.0.1 and ::1 in our /etc/hosts file so that it looks something like this:

127.0.0.1  localhost localhost.localdomain
::1  localhost

That is needed because we have IPv4 and IPv6 both enabled and services like Postfix expect an IPv6 entry in our hosts file.

The problem

state/hosts.present() has a kind of "dublicate" checker (if you like to name it like that): https://github.com/saltstack/salt/blob/develop/salt/states/host.py#L95

That prevents from an assignment of the same alias to multiple IP adresses, including IPv6 entries.

How to reproduce

test.sls

assign_ipv4_localhost:
  host:
    - present
    - ip: 127.0.0.1
    - name: localhost

assign_ipv6_localhost:
  host:
    - present
    - ip: ::1
    - name: localhost
cat /etc/hosts

As you can see salt replies that it will add both host entries, but in fact only one will be written into the /etc/hosts file.

Conclusion

This is pretty easy to fix. The question is if this should be fixed, and if not, how we report this back to the user calling the host state that something is not working as expected.

Kind regards Ralf

rmatulat avatar Dec 01 '15 19:12 rmatulat

Just to add for clearance: When we have a /etc/hosts like this:

127.0.0.1       localhost.localdomain
::1     ip6-localhost ip6-loopback localhost

We can add localhost to 127.0.0.1 successfully with salt 'minion*' hosts.add_host 127.0.0.1 localhost in contrary using the host.present state (see above). So this is not behaving consistently.

rmatulat avatar Dec 02 '15 06:12 rmatulat

Some further context: RFC 6761

6.3.  Domain Name Reservation Considerations for "localhost."

   The domain "localhost." and any names falling within ".localhost."
   are special in the following ways:

   1.  Users are free to use localhost names as they would any other
       domain names.  Users may assume that IPv4 and IPv6 address
       queries for localhost names will always resolve to the respective
       IP loopback address.

Also: http://superuser.com/questions/1005335/how-do-i-ping-localhost-using-ipv6

If you agree I would provide a pull request deleting the current_ip stuff.

rmatulat avatar Dec 02 '15 08:12 rmatulat

@rall0r, you are welcome to send in a pull request, although it is not immediately clear to me whether only removing this check will make state nonidempotent, meaning that multiple runs of the state will result in correspondingly multiple entries in /etc/hosts.

jfindlay avatar Dec 03 '15 18:12 jfindlay

If you do create a pull request, be sure to send it into the 2015.8 branch.

jfindlay avatar Dec 03 '15 18:12 jfindlay

Well, it should not lead to multiple entries because of https://github.com/saltstack/salt/blob/develop/salt/states/host.py#L87, but I will keep an eye on that.

Hopefully I can get a pull request out of the door tomorrow. Thanks!

rmatulat avatar Dec 03 '15 18:12 rmatulat