3 from ansible.module_utils.basic import *
9 if __name__ == '__main__':
11 "new_ntp_servers": {"required":True, "type": list},
14 module = AnsibleModule(argument_spec=fields)
16 new_ntp_servers = module.params['new_ntp_servers']
18 ntp_file = "/etc/ntp.conf"
19 tmp_file = "/etc/ntp.conf.mod"
22 filter = re.compile('^server.*')
24 with open(ntp_file, 'r') as f:
30 if filter.match(line):
35 with open(tmp_file, 'w') as f:
39 #append the new server configuration
40 for server in new_ntp_servers:
41 f.write("server " + server + "\n");
43 os.rename(tmp_file, ntp_file)
45 module.exit_json(changed=True)
47 except Exception as exp:
48 module.fail_json(msg=str(ex))