Skip to content

ANXS/hostname

Repository files navigation

ANXS - hostname

CI Status Maintenance Ansible Role License

Ansible role that sets the hostname and FQDN of a node based on its inventory name, keeping /etc/hostname and /etc/hosts in sync for IPv4 and IPv6.

Requirements & Dependencies

  • Ansible 2.12 or higher.
  • Ubuntu 20.04+ or Debian 12+.
  • Depends on ANXS.apt (installed via Galaxy).

Usage

Add hosts to your inventory with their FQDN (e.g. foo.bar.com), and the role will set the short hostname and FQDN accordingly (hostname: foo, FQDN: foo.bar.com). A bare short name in inventory works too — hostname is set without an attached FQDN.

Variables

Some commonly adjusted variables. See defaults/main.yml for the full set.

  • hostname_avahi (default false) installs avahi-daemon and libnss-mdns for mDNS-based name resolution. Useful for Vagrant and LAN discovery.

Testing

Tests use Molecule with Docker and Testinfra. Run the full suite with make test, or target a specific platform (e.g. make test-ubuntu2404).

The test suite verifies hostname and /etc/hostname are set from inventory, /etc/hosts carries correct IPv4 and IPv6 entries, and the legacy 127.0.1.1 Raspberry Pi override is removed when present. Tests run across Ubuntu 20.04/22.04/24.04 and Debian 12.

Note on AI Usage

This project has been developed with AI assistance. Contributions making use of AI generated content are welcome, however they must be human reviewed prior to submission as pull requests, or issues. All contributors must be able to fully explain and defend any AI generated code, documentation, issues, or tests they submit. Contributions making use of AI must have this explicitly declared in the pull request or issue. This also applies to utilization of AI for reviewing of pull requests.

Feedback, bug-reports, requests, ...

Are welcome!

About

Ansible role to set/update the hostname

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors