Created
March 8, 2013 10:01
-
-
Save roccoblues/5115453 to your computer and use it in GitHub Desktop.
Ansible module to set timezone on hosts. DISCLAIMER: this is probably totally unportable and only tested on Debian 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import time | |
import os | |
from subprocess import call | |
DOCUMENTATION = ''' | |
--- | |
module: timezone | |
short_description: Set timezone on host. | |
description: | |
- The M(timezone) module sets the timezone on a host. | |
options: | |
zone: | |
description: | |
- Timezone to set. | |
required: true | |
default: null | |
aliases: [] | |
examples: | |
- code: "timezone: zone=UTC" | |
description: "Set timezone to UTC" | |
author: Dennis Schoen <dennis@blogma.de> | |
''' | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
zone = dict(required=True) | |
) | |
) | |
zone = module.params.get('zone') | |
if time.tzname[0] == zone: | |
module.exit_json(changed=False) | |
else: | |
os.unlink('/etc/localtime') | |
os.symlink("/usr/share/zoneinfo/%s" % zone, '/etc/localtime') | |
call(['/sbin/hwclock', '--systohc']) | |
module.exit_json(changed=True) | |
# this is magic, see lib/ansible/module_common.py | |
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment