Note
This module is part of ansible-base
and included in all Ansible installations. In most cases, you can use the short module name hostname even without specifying the collections:
keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.
New in version 1.4: of ansible.builtin
systemd
.The below requirements are needed on the host that executes this module.
Parameter | Choices/Defaults | Comments |
---|---|---|
name string / required | 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. | |
use string added in 2.9 of ansible.builtin |
| 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'. |
Note
/etc/hosts
. You need to modify it yourself using other modules such as ansible.builtin.template or ansible.builtin.replace.scutil
to set HostName
, ComputerName
, and LocalHostName
. Since LocalHostName
cannot contain spaces or most special characters, this module will replace characters when setting LocalHostName
.check_mode
.- name: Set a hostname ansible.builtin.hostname: name: web01 - name: Set a hostname specifying strategy ansible.builtin.hostname: name: web01 strategy: systemd
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/ansible/builtin/hostname_module.html