make copy & template module take key/value parameters so we're consistent. Only the command

module works differently now

starter manpage for modules

allow template file location to be passed into template & setup modules
This commit is contained in:
Michael DeHaan 2012-02-26 19:21:44 -05:00
parent e202fea4fa
commit 5e6bf63215
3 changed files with 45 additions and 18 deletions

25
copy
View file

@ -8,14 +8,27 @@ try:
except ImportError: except ImportError:
import simplejson as json import simplejson as json
source = sys.argv[1] # ===========================================
dest = sys.argv[2] # convert arguments of form ensure=running name=foo
# to a dictionary
# FIXME: make more idiomatic
args = " ".join(sys.argv[1:])
items = shlex.split(args)
params = {}
for x in items:
(k, v) = x.split("=")
params[k] = v
src = params['src']
dest = params['dest']
# raise an error if there is no source file # raise an error if there is no src file
if not os.path.exists(source): if not os.path.exists(src):
print json.dumps({ print json.dumps({
"failed" : 1, "failed" : 1,
"msg" : "Source %s failed to transfer" % source "msg" : "Source %s failed to transfer" % src
}) })
sys.exit(1) sys.exit(1)
@ -24,7 +37,7 @@ changed = False
if os.path.exists(dest): if os.path.exists(dest):
md5sum = os.popen("md5sum %s" % dest).read().split()[0] md5sum = os.popen("md5sum %s" % dest).read().split()[0]
os.system("cp %s %s" % (source, dest)) os.system("cp %s %s" % (src, dest))
md5sum2 = os.popen("md5sum %s" % dest).read().split()[0] md5sum2 = os.popen("md5sum %s" % dest).read().split()[0]

19
setup
View file

@ -1,7 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
ANSIBLE_DIR = "/etc/ansible" DEFAULT_ANSIBLE_SETUP = "/etc/ansible/setup"
ANSIBLE_SETUP = "/etc/ansible/setup"
import sys import sys
import os import os
@ -15,28 +14,30 @@ except ImportError:
# load config & template variables # load config & template variables
input_data = sys.argv[1:] input_data = sys.argv[1:]
new_options = dict([ x.split("=") for x in input_data ]) 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 # create the config dir if it doesn't exist
if not os.path.exists(ANSIBLE_DIR): if not os.path.exists(ansible_dir):
os.makedirs(ANSIBLE_DIR) os.makedirs(ansible_dir)
changed = False changed = False
if not os.path.exists(ANSIBLE_SETUP): if not os.path.exists(ansible_file):
changed = True changed = True
else: else:
md5sum = os.popen("md5sum %s" % ANSIBLE_SETUP).read() md5sum = os.popen("md5sum %s" % ansible_file).read()
# write the template/settings file using # write the template/settings file using
# instructions from server # instructions from server
f = open(ANSIBLE_SETUP, "w+") f = open(ansible_file, "w+")
reformat = json.dumps(new_options) reformat = json.dumps(new_options)
f.write(reformat) f.write(reformat)
f.close() f.close()
md5sum2 = os.popen("md5sum %s" % ANSIBLE_SETUP).read() md5sum2 = os.popen("md5sum %s" % ansible_file).read()
if md5sum != md5sum2: if md5sum != md5sum2:
changed = True changed = True

View file

@ -8,9 +8,22 @@ try:
except ImportError: except ImportError:
import simplejson as json import simplejson as json
source = sys.argv[1] # ===========================================
dest = sys.argv[2] # convert arguments of form ensure=running name=foo
metadata = sys.argv[3] # to a dictionary
# FIXME: make more idiomatic
args = " ".join(sys.argv[1:])
items = shlex.split(args)
params = {}
for x in items:
(k, v) = x.split("=")
params[k] = v
source = params['src']
dest = params['dest']
metadata = params.get('metadata', '/etc/ansible/setup')
# raise an error if there is no template metadata # raise an error if there is no template metadata
if not os.path.exists(metadata): if not os.path.exists(metadata):