ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
832 stars 1.53k forks source link

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

Open probitcarwyn opened 2 months ago

probitcarwyn commented 2 months ago

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:

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:

https://github.com/ansible-collections/community.general/blob/e5bc38d856b3db0c436ccf63538bd8def9594dca/plugins/modules/timezone.py#L117-L121

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

https://github.com/ansible-collections/community.general/blob/e5bc38d856b3db0c436ccf63538bd8def9594dca/plugins/modules/timezone.py#L290-L296

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

https://github.com/ansible-collections/community.general/blob/e5bc38d856b3db0c436ccf63538bd8def9594dca/plugins/modules/timezone.py#L363-L384

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

ansibullbot commented 2 months ago

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 commented 2 months ago

cc @indrajitr @jasperla @tmshn click here for bot help