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 - Add AIX support using `chtz` #58838

Merged
merged 5 commits into from Jul 15, 2019

Conversation

Projects
None yet
5 participants
@d-little
Copy link
Contributor

commented Jul 8, 2019

SUMMARY

Adding AIX support to module timezone.

This code does not support posix format, Olson/tz database only (similar to all other implementations). Tested on AIX 7.1 and 7.2, but should work on all AIX 6.1+ instances.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

timezone

ADDITIONAL INFORMATION

There's a small block of commented out code that checks to see if the supplied format is Olson/tzdatabase. This could be used for future additional Posix support, but I do not believe that it would ever be necessary. Just in case someone ever requests it.

Contrary to IBM's man page, chtz pretty much never returns non-zero except when it is unable to update the /etc/environment file. Totally invalid timezones such as aaaBadTimeZoneaaa can be supplied and AIX will happy set TZ=aaaBadTimeZoneaaa in the environment file.

To avoid this we confirm that the supplied Olson/tz database name is found in /usr/share/lib/zoneinfo/'name' before making the change. If the target file does not exist we exit with failure

If the timezone file does exist, we update /etc/environment using chtz name, and then post-check /etc/environment to ensure that TZ=name exists

Examples / Testing

For the given example of Asia/Tokyo:
On the target AIX host, the file exists:

root@AIXSERVER:/ # oslevel -s
7200-01-00-0000
root@AIXSERVER:/ # ls -l /usr/share/lib/zoneinfo/Asia/Tokyo
-rw-r--r--    1 bin      bin             355 Feb  2 2017  /usr/share/lib/zoneinfo/Asia/Tokyo
root@AIXSERVER:/ # file /usr/share/lib/zoneinfo/Asia/Tokyo
/usr/share/lib/zoneinfo/Asia/Tokyo: data or International Language text
root@AIXSERVER:/ # grep '^TZ' /etc/environment
TZ=US/Central

And testing:

Running on a server with a new, valid, timezone
# ansible -vvv AIXSERVER -i /etc/ansible/test.ini -m timezone -a "name=Asia/Tokyo"
--cut--
AIXSERVER | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "diff": {
        "after": {
            "name": "Asia/Tokyo"
        },
        "before": {
            "name": "US/Central"
        }
    },
    "invocation": {
        "module_args": {
            "hwclock": null,
            "name": "Asia/Tokyo"
        }
    }
}
Running on a server with a the existing timezone
# ansible -vvv AIXSERVER -i /etc/ansible/test.ini -m timezone -a "name=Asia/Tokyo"
--cut--
AIXSERVER | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "diff": {
        "after": {
            "name": "Asia/Tokyo"
        },
        "before": {
            "name": "Asia/Tokyo"
        }
    },
    "invocation": {
        "module_args": {
            "hwclock": null,
            "name": "Asia/Tokyo"
        }
    }
}
Running with an invalid timezone
# ansible -vvv AIXSERVER -i /etc/ansible/test.ini -m timezone -a "name=Moon/Lunar-Base"
AIXSERVER | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "hwclock": null,
            "name": "Moon/Lunar-Base"
        }
    },
    "msg": "Moon/Lunar-Base is not a recognized timezone"
@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jul 8, 2019

@d-little d-little changed the title init AIX support timezone - Add AIX support using `chtz` Jul 9, 2019

@d-little

This comment has been minimized.

Copy link
Contributor Author

commented Jul 9, 2019

@mator

This comment has been minimized.

Copy link
Contributor

commented Jul 9, 2019

Why to use required=False, with followup check for chtz presence, if you could use required=True ? Thanks.

        self.settimezone = self.module.get_bin_path('chtz', required=False)
        if not self.settimezone:
            module.fail_json(msg='chtz not found.')```
@d-little

This comment has been minimized.

Copy link
Contributor Author

commented Jul 9, 2019

Why to use required=False, with followup check for chtz presence, if you could use required=True ? Thanks.

Honestly I'm not sure, that was a leftover from a copy/paste from one of the existing classes. I've pushed two updates, one to make chtz required=True and another that refactors the way we check /etc/environment for TZ= values. (added a function instead, and grabs the whole contents of /etc/environment and runs a single re.match)

@gforster

This comment has been minimized.

Copy link
Contributor

commented Jul 9, 2019

LGTM on 7.2. Not sure I can get a 6.x up for testing in a timely fashion.

Sent with GitHawk

@d-little

This comment has been minimized.

Copy link
Contributor Author

commented Jul 14, 2019

@mator How's the new code look, any changes you'd like to see?

@mator

This comment has been minimized.

Copy link
Contributor

commented Jul 15, 2019

works for me

@jctanner jctanner referenced this pull request Jul 15, 2019

Closed

Automerge is broken #1231

@jctanner

This comment has been minimized.

Copy link
Member

commented Jul 15, 2019

bump

@ansibot ansibot removed the needs_triage label Jul 15, 2019

@ansibot ansibot merged commit ee71a7d into ansible:devel Jul 15, 2019

1 check passed

Shippable Run 131342 status is SUCCESS.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.