Repository: ansible-collections/community.general

Issue:
timezone requires tzdata on Alpine Linux
### 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

```console (paste below)
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

```console (paste below)
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

- [X] I agree to follow the Ansible Code of Conduct
timezone requires tzdata on Alpine Linux
### 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

```console (paste below)
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

```console (paste below)
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

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/system/timezone.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/system/timezone.py)

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](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @indrajitr @jasperla @tmshn
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
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?
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](https://data.iana.org/time-zones/tzdb/NEWS), 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:

https://github.com/ansible-collections/community.general/blob/23e7ef025529b7c79fab284121f0b4b5045e45fa/plugins/modules/system/timezone.py#L19

_(Note: Possibly most of other UNIX systems follow same rule, but I'm not sure)._
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+
 ```
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).
```
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
Files identified in the description:
* [`plugins/modules/system/timezone.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/system/timezone.py)

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](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @indrajitr @jasperla @tmshn
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
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?
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](https://data.iana.org/time-zones/tzdb/NEWS), 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:

https://github.com/ansible-collections/community.general/blob/23e7ef025529b7c79fab284121f0b4b5045e45fa/plugins/modules/system/timezone.py#L19

_(Note: Possibly most of other UNIX systems follow same rule, but I'm not sure)._
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+
 ```
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).
```
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

Resolving patch:
diff --git a/plugins/modules/system/timezone.py b/plugins/modules/system/timezone.py
--- a/plugins/modules/system/timezone.py
+++ b/plugins/modules/system/timezone.py
@@ -19,6 +19,8 @@
     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 that the zoneinfo files are installed with the appropriate OS package, like C(tzdata) (usually always installed,
+    when not using a 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+


Test patch: