timezone: Tidy up docs and arg parsing (#20133)

* Small tweaks for timezone module:

- small textual fixes
- ensure the generated docs list either hwclock or name as required
  by using a non-generated value for required_one_of

* Update docs with the DOCUMENTATION block about either name/hwclock being required
This commit is contained in:
Jasper Lievisse Adriaanse 2017-01-11 16:22:27 +01:00 committed by John R Barker
parent 7c6916f8d1
commit b384a0f795

View file

@ -34,19 +34,20 @@ module: timezone
short_description: Configure timezone setting short_description: Configure timezone setting
description: description:
- This module configures the timezone setting, both of the system clock - This module configures the timezone setting, both of the system clock
and of the hardware clock. I(Currently only Linux platform is supported.) and of the hardware clock. I(Currently only the Linux platform is supported).
It is recommended to restart C(crond) after changing the timezone, It is recommended to restart C(crond) after changing the timezone,
otherwise the jobs may run at the wrong time. otherwise the jobs may run at the wrong time.
It uses the C(timedatectl) command if available. Otherwise, it edits It uses the C(timedatectl) command if available. Otherwise, it edits
C(/etc/sysconfig/clock) or C(/etc/timezone) for the system clock, C(/etc/sysconfig/clock) or C(/etc/timezone) for the system clock,
and uses the C(hwclock) command for the hardware clock. and uses the C(hwclock) command for the hardware clock.
If you want to set up the NTP, use M(service) module. If you want to set up the NTP, use M(service) module.
version_added: "2.2.0" version_added: "2.2"
options: options:
name: name:
description: description:
- Name of the timezone for the system clock. - Name of the timezone for the system clock.
Default is to keep current setting. Default is to keep current setting. B(At least one of name and
hwclock are required.)
required: false required: false
hwclock: hwclock:
description: description:
@ -54,6 +55,7 @@ options:
Default is to keep current setting. Default is to keep current setting.
Note that this option is recommended not to change and may fail Note that this option is recommended not to change and may fail
to configure, especially on virtual environments such as AWS. to configure, especially on virtual environments such as AWS.
B(At least one of name and hwclock are required.)
required: false required: false
aliases: ['rtc'] aliases: ['rtc']
author: "Shinichi TAMURA (@tmshn)" author: "Shinichi TAMURA (@tmshn)"
@ -233,7 +235,7 @@ class Timezone(object):
class SystemdTimezone(Timezone): class SystemdTimezone(Timezone):
"""This is a Timezone manipulation class systemd-powered Linux. """This is a Timezone manipulation class for systemd-powered Linux.
It uses the `timedatectl` command to check/set all arguments. It uses the `timedatectl` command to check/set all arguments.
""" """
@ -430,13 +432,12 @@ class NosystemdTimezone(Timezone):
def main(): def main():
# Construct 'module' and 'tz' # Construct 'module' and 'tz'
arg_spec = dict(
hwclock=dict(choices=['UTC', 'local'], aliases=['rtc']),
name =dict(),
)
module = AnsibleModule( module = AnsibleModule(
argument_spec=arg_spec, argument_spec=dict(
required_one_of=[arg_spec.keys()], hwclock=dict(default=None, choices=['UTC', 'local'], aliases=['rtc']),
name=dict(default=None),
),
required_one_of=['hwclock', 'name'],
supports_check_mode=True supports_check_mode=True
) )
tz = Timezone(module) tz = Timezone(module)