ansible.builtin.hostname module – Manage hostname
This module is part of
ansible-core and included in all Ansible
installations. In most cases, you can use the short
hostname even without specifying the collections keyword.
However, we recommend you use the Fully Qualified Collection Name (FQCN)
ansible.builtin.hostname for easy linking to the
module documentation and to avoid conflicting with other collections that may have
the same module name.
Set system’s hostname. Supports most OSs/Distributions including those using
Windows, HP-UX, and AIX are not currently supported.
The below requirements are needed on the host that executes this module.
Name of the host.
If the value is a fully qualified domain name that does not resolve from the given host, this will cause the module to hang for a few seconds while waiting for the name resolution attempt to timeout.
Which strategy to use to update the hostname.
If not set we try to autodetect, but this can be problematic, particularly with containers as they can present misleading information.
Note that ‘systemd’ should be specified for RHEL/EL/CentOS 7+. Older distributions should use ‘redhat’.
Can run in check_mode and return changed status prediction without modifying target
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode
Action returns an
Target OS/families that can be operated against
On macOS, this module uses
LocalHostNamecannot contain spaces or most special characters, this module will replace characters when setting
- name: Set a hostname
- name: Set a hostname specifying strategy