ansible.builtin.hostname – Manage hostname

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

Synopsis

  • Set system’s hostname, supports most OSs/Distributions, including those using systemd.

  • Note, this module does NOT modify /etc/hosts. You need to modify it yourself using other modules like template or replace.

  • Windows, HP-UX and AIX are not currently supported.

Requirements

The below requirements are needed on the host that executes this module.

  • hostname

Parameters

Parameter Choices/Defaults Comments
name
string / required
Name of the host
use
string
added in 2.9 of ansible.builtin
    Choices:
  • generic
  • debian
  • sles
  • redhat
  • alpine
  • systemd
  • openrc
  • openbsd
  • solaris
  • freebsd
Which strategy to use to update the hostname.
If not set we try to autodetect, but this can be problematic, specially with containers as they can present misleading information.

Examples

- name: Set a hostname
  hostname:
    name: web01

Authors

  • Adrian Likins (@alikins)

  • Hideki Saito (@saito-hideki)