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 requires tzdata on Alpine Linux #3242

Closed
1 task done
skyfaller opened this issue Aug 19, 2021 · 7 comments · Fixed by #3876
Closed
1 task done

timezone requires tzdata on Alpine Linux #3242

skyfaller opened this issue Aug 19, 2021 · 7 comments · Fixed by #3876
Labels

Comments

@skyfaller
Copy link

Summary

I cannot update the timezone on Alpine Linux without tzdata installed. It goes like this:

TASK [sunrise : print datetime before setting timezone] **************************************************************************************************************************
ok: [dragon] => {
    "ansible_date_time": {
        "date": "2021-08-19",
        "day": "19",
        "epoch": "1629404309",
        "hour": "20",
        "iso8601": "2021-08-19T20:18:29Z",
        "iso8601_basic": "20210819T201829573104",
        "iso8601_basic_short": "20210819T201829",
        "iso8601_micro": "2021-08-19T20:18:29.573104Z",
        "minute": "18",
        "month": "08",
        "second": "29",
        "time": "20:18:29",
        "tz": "UTC",
        "tz_dst": "UTC",
        "tz_offset": "+0000",
        "weekday": "Thursday",
        "weekday_number": "4",
        "weeknumber": "33",
        "year": "2021"
    }
}

TASK [sunrise : set timezone to NYC] *********************************************************************************************************************************************
fatal: [dragon]: FAILED! => {"changed": false, "msg": "Error message:\ngiven timezone \"America/New_York\" is not available"}

/usr/share/zoneinfo does not seem to exist.

It appears tzdata provides zoneinfo: https://pkgs.alpinelinux.org/contents?file=&path=%2Fusr%2Fshare%2Fzoneinfo*&name=&branch=v3.14

If instead I install tzdata first, timezone works fine, with output like this:

TASK [sunrise : print datetime before setting timezone] **************************************************************************************************************************
ok: [dragon] => {
    "ansible_date_time": {
        "date": "2021-08-19",
        "day": "19",
        "epoch": "1629405156",
        "hour": "20",
        "iso8601": "2021-08-19T20:32:36Z",
        "iso8601_basic": "20210819T203236431305",
        "iso8601_basic_short": "20210819T203236",
        "iso8601_micro": "2021-08-19T20:32:36.431305Z",
        "minute": "32",
        "month": "08",
        "second": "36",
        "time": "20:32:36",
        "tz": "UTC",
        "tz_dst": "UTC",
        "tz_offset": "+0000",
        "weekday": "Thursday",
        "weekday_number": "4",
        "weeknumber": "33",
        "year": "2021"
    }
}

TASK [sunrise : set timezone to NYC] *********************************************************************************************************************************************
changed: [dragon] => {"changed": true, "msg": "Added 1 line and deleted 0 line(s) on /etc/timezone"}

RUNNING HANDLER [sunrise : update facts so we can see if the timezone is correct now] ********************************************************************************************
ok: [dragon]

RUNNING HANDLER [sunrise : print datetime after setting timezone] ****************************************************************************************************************
ok: [dragon] => {
    "ansible_date_time": {
        "date": "2021-08-19",
        "day": "19",
        "epoch": "1629390760",
        "hour": "16",
        "iso8601": "2021-08-19T20:32:40Z",
        "iso8601_basic": "20210819T163240339453",
        "iso8601_basic_short": "20210819T163240",
        "iso8601_micro": "2021-08-19T20:32:40.339453Z",
        "minute": "32",
        "month": "08",
        "second": "40",
        "time": "16:32:40",
        "tz": "EDT",
        "tz_dst": "EDT",
        "tz_offset": "-0400",
        "weekday": "Thursday",
        "weekday_number": "4",
        "weeknumber": "33",
        "year": "2021"
    }
}

Therefore, I believe that the documentation should mention tzdata is necessary on Alpine Linux:
https://pkgs.alpinelinux.org/package/v3.14/main/x86_64/tzdata

Neither the latest nor devel version of this documentation mentions tzdata or Alpine Linux:
https://docs.ansible.com/ansible/latest/collections/community/general/timezone_module.html
https://docs.ansible.com/ansible/devel/collections/community/general/timezone_module.html

Issue Type

Documentation Report

Component Name

timezone

Ansible Version

ansible [core 2.11.3]
  config file = /Users/nelson/.ansible.cfg
  configured module search path = ['/Users/nelson/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/4.4.0/libexec/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/nelson/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.6 (default, Jun 29 2021, 06:20:32) [Clang 12.0.0 (clang-1200.0.32.29)]
  jinja version = 3.0.1
  libyaml = True

Configuration

DEFAULT_HOST_LIST(/Users/nelson/.ansible.cfg) = ['/usr/local/etc/ansible/hosts']
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /Users/nelson/.vault_pass

OS / Environment

macOS Catalina 10.15.7 (19H1323)
Running on a Linode virtual host using their Alpine 3.14 image, which is the latest non-rolling release of Alpine: https://api.linode.com/v4/images
uname -a on the host running Alpine Linux: Linux dragon 5.10.43-0-virt #1-Alpine SMP Fri, 11 Jun 2021 07:41:12 +0000 x86_64 Linux

Additional Information

No response

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 inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@felixfontein
Copy link
Collaborator

I guess adding another note like the one for SmartOS (https://github.com/ansible-collections/community.general/blob/main/plugins/modules/system/timezone.py#L45) should suffice. Would you mind creating a PR?

@tmshn
Copy link

tmshn commented Aug 22, 2021

I believe zoneinfo files (which are usually provided by tzdata package) are required for all Linux systems. The point is: some minimal setups like pure Alpine lack them, which requires explicit installation. And, as another point, timezone database is occasionally updated, so it's better practice to update tzdata package even if it is preinstalled.

So maybe I think it's appropriate to add note here:

For Linux it can use C(timedatectl) or edit C(/etc/sysconfig/clock) or C(/etc/timezone) and C(hwclock).

(Note: Possibly most of other UNIX systems follow same rule, but I'm not sure).

@mator
Copy link
Contributor

mator commented Sep 14, 2021

something like this?

community.general.git]$ git diff
diff --git a/plugins/modules/system/timezone.py b/plugins/modules/system/timezone.py
index 27dfc9a9..2307f0e5 100644
--- a/plugins/modules/system/timezone.py
+++ b/plugins/modules/system/timezone.py
@@ -19,6 +19,8 @@ description:
     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 zoneinfo files installed with approritate OS package, like C(tzdata) (usually always installed),
+    if not minimal installation like Alpine linux.
   - As of Ansible 2.3 support was added for SmartOS and BSDs.
   - As of Ansible 2.4 support was added for macOS.
   - As of Ansible 2.9 support was added for AIX 6.1+

@felixfontein
Copy link
Collaborator

Small copy-editing:

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

@mator mator mentioned this issue Sep 15, 2021
1 task
@russoz
Copy link
Collaborator

russoz commented Dec 8, 2021

Hi @mator any luck working on this? The patch itself is very straightforward, so let us know if you have any issues with the setup.

I have written this small tool I use to save me some of the trouble setting up a test environment for the collection:
https://pypi.org/project/andebox/

I still consider it alpha quality (especially because it is lacking a test suite), but on the other hand, I have been using it constantly for quite a while now.

#shameless #selfpromotion

felixfontein added a commit that referenced this issue Dec 9, 2021
* small docs update for timezone module
fixes #3242

* Update plugins/modules/system/timezone.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
patchback bot pushed a commit that referenced this issue Dec 9, 2021
* small docs update for timezone module
fixes #3242

* Update plugins/modules/system/timezone.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c14eafd)
patchback bot pushed a commit that referenced this issue Dec 9, 2021
* small docs update for timezone module
fixes #3242

* Update plugins/modules/system/timezone.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c14eafd)
felixfontein pushed a commit that referenced this issue Dec 9, 2021
* small docs update for timezone module
fixes #3242

* Update plugins/modules/system/timezone.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c14eafd)

Co-authored-by: Anatoly Pugachev <matorola@gmail.com>
felixfontein pushed a commit that referenced this issue Dec 9, 2021
* small docs update for timezone module
fixes #3242

* Update plugins/modules/system/timezone.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c14eafd)

Co-authored-by: Anatoly Pugachev <matorola@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants