diff options
author | Matt Woodson <mwoodson@gmail.com> | 2016-01-18 15:47:54 -0500 |
---|---|---|
committer | Matt Woodson <mwoodson@gmail.com> | 2016-01-18 15:47:54 -0500 |
commit | 6fe8100badf6be308f89a690646811af9891633e (patch) | |
tree | d8b22ed79c472edba4bbbf81bce20dbe9d4ee9f0 /roles/lib_timedatectl/library | |
parent | ee3aec770b6b1a2b0212b432a920e3d846e56044 (diff) | |
parent | a1c9b13d81d8c94c7764524809f5419a5d3ff73d (diff) | |
download | openshift-6fe8100badf6be308f89a690646811af9891633e.tar.gz openshift-6fe8100badf6be308f89a690646811af9891633e.tar.bz2 openshift-6fe8100badf6be308f89a690646811af9891633e.tar.xz openshift-6fe8100badf6be308f89a690646811af9891633e.zip |
Merge pull request #1218 from mwoodson/chrony
new role: chrony so that servers can use ntp
Diffstat (limited to 'roles/lib_timedatectl/library')
-rw-r--r-- | roles/lib_timedatectl/library/timedatectl.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/roles/lib_timedatectl/library/timedatectl.py b/roles/lib_timedatectl/library/timedatectl.py new file mode 100644 index 000000000..b6eab5918 --- /dev/null +++ b/roles/lib_timedatectl/library/timedatectl.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +''' + timedatectl ansible module + + This module supports setting ntp enabled +''' +import subprocess + + + + +def do_timedatectl(options=None): + ''' subprocess timedatectl ''' + + cmd = ['/usr/bin/timedatectl'] + if options: + cmd += options.split() + + proc = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE) + proc.wait() + return proc.stdout.read() + +def main(): + ''' Ansible module for timedatectl + ''' + + module = AnsibleModule( + argument_spec=dict( + #state=dict(default='enabled', type='str'), + ntp=dict(default=True, type='bool'), + ), + #supports_check_mode=True + ) + + # do something + ntp_enabled = False + + results = do_timedatectl() + + for line in results.split('\n'): + if 'NTP enabled' in line: + if 'yes' in line: + ntp_enabled = True + + ######## + # Enable NTP + ######## + if module.params['ntp']: + if ntp_enabled: + module.exit_json(changed=False, results="enabled", state="enabled") + + # Enable it + # Commands to enable ntp + else: + results = do_timedatectl('set-ntp yes') + module.exit_json(changed=True, results="enabled", state="enabled", cmdout=results) + + ######### + # Disable NTP + ######### + else: + if not ntp_enabled: + module.exit_json(changed=False, results="disabled", state="disabled") + + results = do_timedatectl('set-ntp no') + module.exit_json(changed=True, results="disabled", state="disabled") + + module.exit_json(failed=True, changed=False, results="Something went wrong", state="unknown") + +# Pylint is getting in the way of basic Ansible +# pylint: disable=redefined-builtin,wildcard-import,unused-wildcard-import +from ansible.module_utils.basic import * + +main() |