ansible.builtin.hostname (v2.16.5) — module

Manage hostname

| "added in version" 1.4 of ansible.builtin"

Authors: Adrian Likins (@alikins), Hideki Saito (@saito-hideki)

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

Set system's hostname. Supports most OSs/Distributions including those using C(systemd).

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


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set a hostname
  ansible.builtin.hostname:
    name: web01
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set a hostname specifying strategy
  ansible.builtin.hostname:
    name: web01
    use: systemd

Inputs

    
use:
    choices:
    - alpine
    - debian
    - freebsd
    - generic
    - macos
    - macosx
    - darwin
    - openbsd
    - openrc
    - redhat
    - sles
    - solaris
    - systemd
    description:
    - 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'.
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

name:
    description:
    - 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.
    required: true
    type: str