Templating as non-root should not require passing in the metadata= parameter.

This commit is contained in:
Michael DeHaan 2012-03-05 22:23:56 -05:00
parent 4ee4ddcd7c
commit 0935506d6f
2 changed files with 20 additions and 3 deletions

View file

@ -306,8 +306,6 @@ class PlayBook(object):
push_var_str='' push_var_str=''
for (k,v) in vars.items(): for (k,v) in vars.items():
push_var_str += "%s=%s " % (k,v) push_var_str += "%s=%s " % (k,v)
if user != 'root':
push_var_str = "%s metadata=~/.ansible_setup" % (push_var_str)
# push any variables down to the system # push any variables down to the system
setup_results = ansible.runner.Runner( setup_results = ansible.runner.Runner(

View file

@ -213,6 +213,16 @@ class Runner(object):
args = [ str(x) for x in module_args ] args = [ str(x) for x in module_args ]
args = " ".join(args) args = " ".join(args)
inject_vars = self.setup_cache.get(conn._host,{}) inject_vars = self.setup_cache.get(conn._host,{})
# the metadata location for the setup module is transparently managed
# since it's an 'internals' module, kind of a black box. See playbook
# other modules are not allowed to have this kind of handling
if remote_module_path.endswith("/setup") and args.find("metadata=") == -1:
if self.remote_user == 'root':
args = "%s metadata=/etc/ansible/setup" % args
else:
args = "%s metadata=~/.ansible/setup" % args
template = jinja2.Template(args) template = jinja2.Template(args)
args = template.render(inject_vars) args = template.render(inject_vars)
@ -227,7 +237,9 @@ class Runner(object):
because those require extra work. because those require extra work.
''' '''
module = self._transfer_module(conn, tmp, self.module_name) module = self._transfer_module(conn, tmp, self.module_name)
result = self._execute_module(conn, tmp, module, self.module_args) result = self._execute_module(conn, tmp, module, self.module_args)
# when running the setup module, which pushes vars to the host and ALSO # when running the setup module, which pushes vars to the host and ALSO
# returns them (+factoids), store the variables that were returned such that commands # returns them (+factoids), store the variables that were returned such that commands
# run AFTER setup use these variables for templating when executed # run AFTER setup use these variables for templating when executed
@ -238,6 +250,7 @@ class Runner(object):
var_result = json.loads(result) var_result = json.loads(result)
except: except:
var_result = {} var_result = {}
self._delete_remote_files(conn, tmp) self._delete_remote_files(conn, tmp)
return self._return_from_module(conn, host, result) return self._return_from_module(conn, host, result)
@ -293,7 +306,13 @@ class Runner(object):
options = self._parse_kv(self.module_args) options = self._parse_kv(self.module_args)
source = options['src'] source = options['src']
dest = options['dest'] dest = options['dest']
metadata = options.get('metadata', '/etc/ansible/setup') metadata = options.get('metadata', None)
if metadata is None:
if self.remote_user == 'root':
metadata = '/etc/ansible/setup'
else:
metadata = '~/.ansible/setup'
# first copy the source template over # first copy the source template over
tpath = tmp tpath = tmp