2012-02-24 09:25:09 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2012-02-27 01:21:44 +01:00
|
|
|
DEFAULT_ANSIBLE_SETUP = "/etc/ansible/setup"
|
2012-02-24 09:25:09 +01:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
|
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
import simplejson as json
|
|
|
|
|
|
|
|
# load config & template variables
|
|
|
|
|
|
|
|
input_data = sys.argv[1:]
|
2012-02-27 01:21:44 +01:00
|
|
|
new_options = dict([ x.split('=') for x in input_data ])
|
|
|
|
ansible_file = new_options.get('metadata', DEFAULT_ANSIBLE_SETUP)
|
2012-02-27 01:55:26 +01:00
|
|
|
ansible_dir = os.path.dirname(ansible_file)
|
2012-02-24 09:25:09 +01:00
|
|
|
|
|
|
|
# create the config dir if it doesn't exist
|
|
|
|
|
2012-02-27 01:21:44 +01:00
|
|
|
if not os.path.exists(ansible_dir):
|
|
|
|
os.makedirs(ansible_dir)
|
2012-02-24 09:25:09 +01:00
|
|
|
|
|
|
|
changed = False
|
2012-02-27 01:55:26 +01:00
|
|
|
md5sum = None
|
2012-02-27 01:21:44 +01:00
|
|
|
if not os.path.exists(ansible_file):
|
2012-02-24 09:25:09 +01:00
|
|
|
changed = True
|
|
|
|
else:
|
2012-02-27 01:21:44 +01:00
|
|
|
md5sum = os.popen("md5sum %s" % ansible_file).read()
|
2012-02-24 09:25:09 +01:00
|
|
|
|
|
|
|
# write the template/settings file using
|
|
|
|
# instructions from server
|
|
|
|
|
2012-02-27 01:21:44 +01:00
|
|
|
f = open(ansible_file, "w+")
|
2012-02-24 09:25:09 +01:00
|
|
|
reformat = json.dumps(new_options)
|
|
|
|
f.write(reformat)
|
|
|
|
f.close()
|
|
|
|
|
2012-02-27 01:21:44 +01:00
|
|
|
md5sum2 = os.popen("md5sum %s" % ansible_file).read()
|
2012-02-24 09:25:09 +01:00
|
|
|
|
|
|
|
if md5sum != md5sum2:
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
result = {
|
|
|
|
"changed" : changed,
|
|
|
|
"md5sum" : md5sum
|
|
|
|
}
|
|
|
|
|
|
|
|
print json.dumps(result)
|