mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
e5f62f20b1
module works differently now starter manpage for modules allow template file location to be passed into template & setup modules
50 lines
992 B
Python
Executable file
50 lines
992 B
Python
Executable file
#!/usr/bin/python
|
|
|
|
DEFAULT_ANSIBLE_SETUP = "/etc/ansible/setup"
|
|
|
|
import sys
|
|
import os
|
|
import shlex
|
|
|
|
try:
|
|
import json
|
|
except ImportError:
|
|
import simplejson as json
|
|
|
|
# load config & template variables
|
|
|
|
input_data = sys.argv[1:]
|
|
new_options = dict([ x.split('=') for x in input_data ])
|
|
ansible_file = new_options.get('metadata', DEFAULT_ANSIBLE_SETUP)
|
|
ansible_dir = os.path.dirname(metadata)
|
|
|
|
# create the config dir if it doesn't exist
|
|
|
|
if not os.path.exists(ansible_dir):
|
|
os.makedirs(ansible_dir)
|
|
|
|
changed = False
|
|
if not os.path.exists(ansible_file):
|
|
changed = True
|
|
else:
|
|
md5sum = os.popen("md5sum %s" % ansible_file).read()
|
|
|
|
# write the template/settings file using
|
|
# instructions from server
|
|
|
|
f = open(ansible_file, "w+")
|
|
reformat = json.dumps(new_options)
|
|
f.write(reformat)
|
|
f.close()
|
|
|
|
md5sum2 = os.popen("md5sum %s" % ansible_file).read()
|
|
|
|
if md5sum != md5sum2:
|
|
changed = True
|
|
|
|
result = {
|
|
"changed" : changed,
|
|
"md5sum" : md5sum
|
|
}
|
|
|
|
print json.dumps(result)
|