ansible-collections / community.general

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

timezone module fails to set time zone when using a time zone alias on Docker Debian #7498

Open blackwood821 opened 10 months ago

blackwood821 commented 10 months ago

Summary

Not able to change the time zone using the timezone module against debian:bullseye Docker container as the remote host.

Here is a sample playbook that succeeds on Debian 11 outside of Docker:

- name: Test playbook
  hosts: all
  remote_user: root
  vars:
    time_zone: US/Pacific
  tasks:
    - name: Set timezone to {{ time_zone }}
      community.general.timezone:
        name: "{{ time_zone }}"

Here is the result:

$ ansible-playbook -i 10.10.50.37, test.yml 

PLAY [Test playbook] *********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************
ok: [10.10.50.37]

TASK [Set timezone to US/Pacific] ********************************************************************************************************************************************************************************************************
ok: [10.10.50.37]

PLAY RECAP *******************************************************************************************************************************************************************************************************************************
10.10.50.37                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

When I run the same thing against a clean debian:bullseye Docker container I get the following error:

$ ansible-playbook -c docker -i tender_zhukovsky, test.yml 

PLAY [Test playbook] *********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************
ok: [tender_zhukovsky]

TASK [Set timezone to US/Pacific] ********************************************************************************************************************************************************************************************************
fatal: [tender_zhukovsky]: FAILED! => {"changed": false, "msg": "Error message:\nstill not desired state, though changes have made - planned: {'name': 'US/Pacific'}, after: {'name': 'America/Los_Angeles'}\nOther message(s):\nAdded 1 line and deleted 1 line(s) on /etc/timezone"}

PLAY RECAP *******************************************************************************************************************************************************************************************************************************
tender_zhukovsky           : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0 

On both systems the US/Pacific time zone alias is a symlink to America/Los_Angeles but for some reason it doesn't work on Docker.

Issue Type

Bug Report

Component Name

timezone

Ansible Version

$ ansible --version
ansible [core 2.15.4]
  config file = /Users/chad/.ansible.cfg
  configured module search path = ['/Users/chad/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/8.4.0/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/chad/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] (/opt/homebrew/Cellar/ansible/8.4.0/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /opt/homebrew/Cellar/ansible/8.4.0/libexec/lib/python3.11/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.4.0

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = /Users/chad/.ansible.cfg
DEFAULT_HOST_LIST(/Users/chad/.ansible.cfg) = ['/Users/chad/.ansible/hosts']

OS / Environment

macOS Ventura 13.5.1

Steps to Reproduce

- name: Test playbook
  hosts: all
  remote_user: root
  vars:
    time_zone: US/Pacific
  tasks:
    - name: Set timezone to {{ time_zone }}
      community.general.timezone:
        name: "{{ time_zone }}"

Expected Results

I expected the task to succeed and change the time zone.

Actual Results

fatal: [tender_zhukovsky]: FAILED! => {"changed": false, "msg": "Error message:\nstill not desired state, though changes have made - planned: {'name': 'US/Pacific'}, after: {'name': 'America/Los_Angeles'}\nOther message(s):\nAdded 1 line and deleted 1 line(s) on /etc/timezone"}

Code of Conduct

blackwood821 commented 10 months ago

It appears to fail when timedatectl is not available which is the case on the Docker container.

ansibullbot commented 10 months ago

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

russoz commented 10 months ago

Hi @blackwood821 thanks for reporting. I am checking the code and not having timedatectl makes the code assume it is a NosystemdTimezone. In theory that should work too, but that error message you see if because the before and after values are different.

It would seem the Nosystemd code is not taking some things into account:

  1. the US/Pacific seems to have been translated into America/Los_Angeles
  2. There is this additional content after the name of the TZ in the after result.

I am trying to replicate the error in a test here.