Browse code

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

Michael DeHaan authored on 2012/03/06 12:23:56
Showing 2 changed files
... ...
@@ -306,8 +306,6 @@ class PlayBook(object):
306 306
         push_var_str=''
307 307
         for (k,v) in vars.items():
308 308
             push_var_str += "%s=%s " % (k,v)
309
-        if user != 'root':
310
-            push_var_str = "%s metadata=~/.ansible_setup" % (push_var_str)
311 309
 
312 310
         # push any variables down to the system
313 311
         setup_results = ansible.runner.Runner(
... ...
@@ -213,6 +213,16 @@ class Runner(object):
213 213
             args = [ str(x) for x in module_args ]
214 214
             args = " ".join(args)
215 215
         inject_vars = self.setup_cache.get(conn._host,{})
216
+
217
+        # the metadata location for the setup module is transparently managed
218
+        # since it's an 'internals' module, kind of a black box. See playbook
219
+        # other modules are not allowed to have this kind of handling
220
+        if remote_module_path.endswith("/setup") and args.find("metadata=") == -1:
221
+            if self.remote_user == 'root':
222
+                args = "%s metadata=/etc/ansible/setup" % args
223
+            else:
224
+                args = "%s metadata=~/.ansible/setup" % args
225
+
216 226
         template = jinja2.Template(args)
217 227
         args = template.render(inject_vars)
218 228
 
... ...
@@ -227,7 +237,9 @@ class Runner(object):
227 227
         because those require extra work.
228 228
         '''
229 229
         module = self._transfer_module(conn, tmp, self.module_name)
230
+
230 231
         result = self._execute_module(conn, tmp, module, self.module_args)
232
+
231 233
         # when running the setup module, which pushes vars to the host and ALSO
232 234
         # returns them (+factoids), store the variables that were returned such that commands
233 235
         # run AFTER setup use these variables for templating when executed
... ...
@@ -238,6 +250,7 @@ class Runner(object):
238 238
                 var_result = json.loads(result)
239 239
             except:
240 240
                 var_result = {}
241
+
241 242
         self._delete_remote_files(conn, tmp)
242 243
         return self._return_from_module(conn, host, result)
243 244
 
... ...
@@ -293,7 +306,13 @@ class Runner(object):
293 293
         options  = self._parse_kv(self.module_args)
294 294
         source   = options['src']
295 295
         dest     = options['dest']
296
-        metadata = options.get('metadata', '/etc/ansible/setup')
296
+        metadata = options.get('metadata', None)
297
+
298
+        if metadata is None:
299
+            if self.remote_user == 'root':
300
+                metadata = '/etc/ansible/setup'
301
+            else:
302
+                metadata = '~/.ansible/setup'
297 303
 
298 304
         # first copy the source template over
299 305
         tpath = tmp