zester
GuidesModules

host

The host.* family of state modules.

ModuleSummary
host.absentEnsure a hostname is absent from the hosts file.
host.presentEnsure a hostname maps to an IP address in the hosts file.

All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.


Family Parameters

These parameters are declared once by the family's shared parameter components — every member that exposes one accepts the identical contract.

ParameterTypeRequiredDefaultDescription
config (alias path)stringNo/etc/hostshosts file path; the path alias is also accepted; defaults to /etc/hosts

host.absent

Ensure a hostname is absent from the hosts file.

Source: pkg/state/modules/host/host_absent.go


host.absent ensures a hostname (name, defaulting to the state ID) does not appear in the hosts file (/etc/hosts by default; override with config or its path alias). The hostname is removed from every line it appears on; a line left with no remaining names is dropped.


Parameters

ParameterTypeRequiredDefaultDescription
namestringNoState IDhost name to remove from the hosts file; defaults to the state ID

host.absent also accepts the family parameter config — see Family Parameters.


Effects

Check

Reads the hosts file (a non-not-exist read error fails the phase). Reports no change when the file does not exist or the hostname is already absent; otherwise reports a change.

Apply

Reads the hosts file and, when the hostname is present, memoizes the prior content for revert and rewrites the file with the hostname removed from every line (dropping any line left with no names). A missing file or an already-absent hostname is a clean no-op. Reports the hostname and path in its details.

Revert

Restores the hosts file to the content this run's Apply captured before removing the hostname. A fresh instance (a standalone revert) recorded nothing and is an explicit clean no-op — it never rewrites a hosts file it did not touch.


Examples

Remove a hostname

The hostname defaults to the state ID.

old-host:
  host.absent: []

Remove a host mapping ad hoc

The bare positional argument is the hostname.

zester '*' host.absent old-host

See Also


host.present

Ensure a hostname maps to an IP address in the hosts file.

Source: pkg/state/modules/host/host_present.go


host.present ensures a hostname (name, defaulting to the state ID) is mapped to ip in the hosts file (/etc/hosts by default; override with config or its path alias). It adds the hostname to an existing line for that IP or appends a new line, and REMOVES the hostname from any line that maps it to a different IP — so a host is never listed under two addresses. ip is required.


Parameters

ParameterTypeRequiredDefaultDescription
namestringNoState IDhost name to manage; defaults to the state ID
ipstringYes(none)IP address the hostname should map to; required

host.present also accepts the family parameter config — see Family Parameters.


Effects

Check

Reads the hosts file (a non-not-exist read error fails the phase rather than risking a blind overwrite) and computes the desired content. Reports a change when the desired mapping is not already present — the hostname is absent, mapped to a different IP, or on a line that would be rewritten.

Apply

Reads the hosts file, memoizes its prior content (or that it did not exist) for revert, and rewrites it so the hostname maps to ip: the hostname is added to the existing line for that IP or a new line is appended, and it is dropped from any line for a different IP (a line left with no names is removed). An already-correct mapping is a clean no-op. Reports the hostname, IP, and path in its details.

Revert

Restores what this run's Apply changed: a hosts file that pre-existed is rewritten with its captured prior content; a file this instance created is removed. A fresh instance (a standalone revert) recorded nothing and is an explicit clean no-op — it never rewrites or deletes a hosts file it did not touch.


Examples

Map a hostname to an IP

The hostname defaults to the state ID; ip is required.

web1:
  host.present:
    - ip: 10.0.0.5

Manage an alternate hosts file

config (or its path alias) overrides the default /etc/hosts.

db-primary:
  host.present:
    - ip: 10.0.0.9
    - config: /etc/hosts

Add a host mapping ad hoc

The bare positional argument is the hostname; ip is a key=value.

zester '*' host.present web1 ip=10.0.0.5

See Also

On this page