ANXS - hostname
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.
- Ansible 2.12 or higher.
- Ubuntu 20.04+ or Debian 12+.
- Depends on
ANXS.apt(installed via Galaxy).
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.
Some commonly adjusted variables. See defaults/main.yml for the full set.
hostname_avahi(defaultfalse) installsavahi-daemonandlibnss-mdnsfor mDNS-based name resolution. Useful for Vagrant and LAN discovery.
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.
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.
Are welcome!