Description
Summary
The community.general.timezone
module incorrectly falls back to non-systemd logic on Fedora when timedatectl
exists but fails to execute — a common scenario in containers where systemd is installed but not fully functional (e.g., missing D-Bus or systemd not being PID 1). As a result, the module edits /etc/sysconfig/clock
and calls hwclock
, which are ignored on modern Fedora, leading to a state mismatch and task failure.
The detection logic should be improved to robustly detect systemd presence (e.g., via /run/systemd/system
) instead of relying solely on the success of timedatectl
.
This might only affect containerized Fedora setups, not full Fedora installations.
Issue Type
Bug Report
Component Name
timezone
Ansible Version
$ ansible --version
ansible [core 2.18.3]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /venv3.12/lib/python3.12/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /venv3.12/bin/ansible
python version = 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] (/venv3.12/bin/python)
jinja version = 3.1.6
libyaml = True
Community.general Version
devel
Configuration
$ ansible-config dump --only-changed
OS / Environment
Reproduced on Fedora 40,41 and 42
Steps to Reproduce
On one of the aforementioned Fedora versions, run the integration tests of timezone
:
ansible-test integration timezone -vvv --allow-destructive --requirements --allow-root --continue-on-error
in order to trigger this test:
community.general/tests/integration/targets/timezone/tasks/test.yml
Lines 301 to 303 in e853a6f
Expected Results
On OpenSUSE, RHEL, Rocky, Debian and Ubuntu the test succeeds with a changed
status.
TASK [timezone : set hwclock to local] *****************************************
changed: [testhost]
Actual Results
On Fedora this test fails:
TASK [timezone : set hwclock to local] *****************************************
task path: /root/.ansible/collections/ansible_collections/community/general/tests/output/.tmp/integration/timezone-ts5x_5uh-ÅÑŚÌβŁÈ/tests/integration/targets/timezone/tasks/test.yml:301
Using module file /root/.ansible/collections/ansible_collections/community/general/plugins/modules/timezone.py
Pipelining is enabled.
<172.18.0.29> ESTABLISH SSH CONNECTION FOR USER: root
<172.18.0.29> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/root/.ansible/test/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/22c8e59cfd"' 172.18.0.29 '/bin/sh -c '"'"'/usr/bin/python3.12 && sleep 0'"'"''
<172.18.0.29> (1, b'\n{"failed": true, "msg": "Error message:\\nstill not desired state, though changes have made - planned: {\'hwclock\': \'local\'}, after: {\'hwclock\': \'UTC\'}\\nOther message(s):\\nAdded 1 line and deleted 0 line(s) on /etc/sysconfig/clock\\nexecuted `/usr/sbin/hwclock --systohc --localtime`", "invocation": {"module_args": {"hwclock": "local", "name": null}}}\n', b"OpenSSH_9.6p1 Ubuntu-3ubuntu13.9, OpenSSL 3.0.13 30 Jan 2024\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 172.18.0.29 is address\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/root/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/root/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master at '/root/.ansible/cp/22c8e59cfd'\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 106\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet_timeout: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n")
<172.18.0.29> Failed to connect to the host via ssh: OpenSSH_9.6p1 Ubuntu-3ubuntu13.9, OpenSSL 3.0.13 30 Jan 2024
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 172.18.0.29 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/root/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/root/.ssh/known_hosts2'
debug1: auto-mux: Trying existing master at '/root/.ansible/cp/22c8e59cfd'
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 106
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet_timeout: read header failed: Broken pipe
debug2: Received exit status from master 1
fatal: [testhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"hwclock": "local",
"name": null
}
},
"msg": "Error message:\nstill not desired state, though changes have made - planned: {'hwclock': 'local'}, after: {'hwclock': 'UTC'}\nOther message(s):\nAdded 1 line and deleted 0 line(s) on /etc/sysconfig/clock\nexecuted `/usr/sbin/hwclock --systohc --localtime`"
}
Code of Conduct
- I agree to follow the Ansible Code of Conduct