community.general.timezone (8.5.0) — module

Configure timezone setting

Authors: Shinichi TAMURA (@tmshn), Jasper Lievisse Adriaanse (@jasperla), Indrajit Raychaudhuri (@indrajitr)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

This module configures the timezone setting, both of the system clock and of the hardware clock. If you want to set up the NTP, use M(ansible.builtin.service) module.

It is recommended to restart C(crond) after changing the timezone, otherwise the jobs may run at the wrong time.

Several different tools are used depending on the OS/Distribution involved. For Linux it can use C(timedatectl) or edit C(/etc/sysconfig/clock) or C(/etc/timezone) and C(hwclock). On SmartOS, C(sm-set-timezone), for macOS, C(systemsetup), for BSD, C(/etc/localtime) is modified. On AIX, C(chtz) is used.

Make sure that the zoneinfo files are installed with the appropriate OS package, like C(tzdata) (usually always installed, when not using a minimal installation like Alpine Linux).

Windows and HPUX are not supported, please let us know if you find any other OS/distro in which this fails.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set timezone to Asia/Tokyo
  community.general.timezone:
    name: Asia/Tokyo

Inputs

    
name:
    description:
    - Name of the timezone for the system clock.
    - Default is to keep current setting.
    - B(At least one of name and hwclock are required.)
    type: str

hwclock:
    aliases:
    - rtc
    choices:
    - local
    - UTC
    description:
    - Whether the hardware clock is in UTC or in local timezone.
    - Default is to keep current setting.
    - Note that this option is recommended not to change and may fail to configure, especially
      on virtual environments such as AWS.
    - B(At least one of name and hwclock are required.)
    - I(Only used on Linux.)
    type: str

Outputs

diff:
  contains:
    after:
      description: The values after change
      type: dict
    before:
      description: The values before change
      type: dict
  description: The differences about the given arguments.
  returned: success
  type: complex