salt.modules.hosts

Manage the information in the hosts file

salt.modules.hosts.add_host(ip, alias)

Add a host to an existing entry, if the entry is not in place then create it with the given host

CLI 范例:

salt '*' hosts.add_host <ip> <alias>
salt.modules.hosts.get_alias(ip)

Return the list of aliases associated with an ip

Aliases (host names) are returned in the order in which they appear in the hosts file. If there are no aliases associated with the IP, an empty list is returned.

CLI 范例:

salt '*' hosts.get_alias <ip addr>
salt.modules.hosts.get_ip(host)

Return the ip associated with the named host

CLI 范例:

salt '*' hosts.get_ip <hostname>
salt.modules.hosts.has_pair(ip, alias)

Return true if the alias is set

CLI 范例:

salt '*' hosts.has_pair <ip> <alias>
salt.modules.hosts.list_hosts()

Return the hosts found in the hosts file in this format:

{'<ip addr>': ['alias1', 'alias2', ...]}

CLI 范例:

salt '*' hosts.list_hosts
salt.modules.hosts.rm_host(ip, alias)

Remove a host entry from the hosts file

CLI 范例:

salt '*' hosts.rm_host <ip> <alias>
salt.modules.hosts.set_host(ip, alias)

Set the host entry in the hosts file for the given ip, this will overwrite any previous entry for the given ip

在 2016.3.0 版更改: If alias does not include any host names (it is the empty string or contains only whitespace), all entries for the given IP address are removed.

CLI 范例:

salt '*' hosts.set_host <ip> <alias>