Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone module incorrectly assumes systemd based Debian doesn't need /etc/timezone Changed #8784

Open
1 task done
probitcarwyn opened this issue Aug 20, 2024 · 2 comments
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type)

Comments

@probitcarwyn
Copy link

Summary

The community.general.timezone module incorrectly assumes systemd based Debian 12 doesn't need the contents of the /etc/timezone to be altered on Debian 12 (bookworm).

Debian tried to remove the use of /etc/timezone in Debian 12 (bookworm) as noted in: https://wiki.debian.org/TimeZoneChanges

Consider the localtime(5) link as the primary source and /etc/timezone as a legacy. During Bookworm release cycle there was an attempt to get rid of /etc/timezone (822733), but it was restored for a while since there is a number of packages still relying on it (1031395).

The Ansible timezone module has distinct code paths for Systemd vs Non-Systemd based systems that basically does:

  • Uses timedatectl (seemingly exclusively) for systemd based systems.
  • Mangles distro specific files for the non systemd case.

Debian 12 (bookworm) is correctly detected as a systemd based system, but as per the Debian docs linked above, Debian 12 still needs /etc/timezone edited as well.

The code that detects systemd is here:

if rc == 0:
return super(Timezone, SystemdTimezone).__new__(SystemdTimezone)
else:
module.debug('timedatectl command was found but not usable: %s. using other method.' % stderr)
return super(Timezone, NosystemdTimezone).__new__(NosystemdTimezone)

But then the SystemdTimezone code path only uses timedatectl to update the /etc/localtime symlink, but does not update/etc/timezone`.

def __init__(self, module):
super(SystemdTimezone, self).__init__(module)
self.timedatectl = module.get_bin_path('timedatectl', required=True)
self.status = dict()
# Validate given timezone
if 'name' in self.value:
self._verify_timezone()

... while the code path for NosystemdTimezone does edit /etc/timezone:

def __init__(self, module):
super(NosystemdTimezone, self).__init__(module)
# Validate given timezone
planned_tz = ''
if 'name' in self.value:
tzfile = self._verify_timezone()
planned_tz = self.value['name']['planned']
# `--remove-destination` is needed if /etc/localtime is a symlink so
# that it overwrites it instead of following it.
self.update_timezone = ['%s --remove-destination %s /etc/localtime' % (self.module.get_bin_path('cp', required=True), tzfile)]
self.update_hwclock = self.module.get_bin_path('hwclock', required=True)
distribution = get_distribution()
self.conf_files['name'] = '/etc/timezone'
self.regexps['name'] = re.compile(r'^([^\s]+)', re.MULTILINE)
self.tzline_format = '%s\n'
# Distribution-specific configurations
if self.module.get_bin_path('dpkg-reconfigure') is not None:
# Debian/Ubuntu
if 'name' in self.value:
self.update_timezone = ['%s -sf %s /etc/localtime' % (self.module.get_bin_path('ln', required=True), tzfile),
'%s --frontend noninteractive tzdata' % self.module.get_bin_path('dpkg-reconfigure', required=True)]
self.conf_files['hwclock'] = '/etc/default/rcS'

Issue Type

Bug Report

Component Name

timezone

Ansible Version

$ ansible --version
ansible [core 2.16.9]
  config file = /home/foo/Projects/ansible/ansible.cfg
  configured module search path = ['/home/foo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/foo/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.4 (main, Jun  7 2024, 00:00:00) [GCC 14.1.1 20240607 (Red Hat 14.1.1-5)] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /usr/lib/python3.12/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.6.3  

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = /home/foo/Projects/ansible/ansible.cfg
DEFAULT_BECOME(/home/foo/Projects/ansible/ansible.cfg) = True
DEFAULT_HOST_LIST(/home/foo/Projects/ansible/ansible.cfg) = ['/home/foo/Projects/ansible/inventory/none.yml']
EDITOR(env: EDITOR) = /usr/bin/nano
HOST_KEY_CHECKING(/home/foo/Projects/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/home/foo/Projects/ansible/ansible.cfg) = ['gcp_compute', 'host_list', 'script', 'auto', 'yaml', 'ini', 'toml']

OS / Environment

Fedora 40

Steps to Reproduce

tasks:
    - name: Set Time Zone
      community.general.timezone:
        name: "Europe/London"

Expected Results

Expected all files that need changing on Debian 12 (bookworm) as per https://wiki.debian.org/TimeZoneChanges to be updated with the Europe/London timezone data.

Actual Results

While the /etc/localtime symlink is updated to point at the correct timezone file.

The contents of the /etc/timezone file is not changed.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) labels Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type)
Projects
None yet
Development

No branches or pull requests

2 participants