From 04aecdcf347ad56e7328718884533a6d864ca3b9 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 2 Apr 2012 13:29:12 -0400 Subject: [PATCH 1/2] before we run the actual module/command - emit what that would be to the logs --- lib/ansible/runner.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index 3d83640fb49..0295b1fb0cb 100755 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -357,6 +357,12 @@ class Runner(object): cmd = "%s %s" % (remote_module_path, argsfile) else: cmd = " ".join([str(x) for x in [remote_module_path, async_jid, async_limit, async_module, argsfile]]) + + # log command as the full command not as the path to args file - helps with debugging + msg = '%s: "%s"' % (self.module_name, args) + conn.exec_command('/usr/bin/logger -t ansible -p auth.info "%s"' % msg, None) + + res, err = self._exec_command(conn, cmd, tmp, sudoable=True) return ( res, err, client_executed_str ) From bcef25f7eb2d3eab486e296c6d97fa08bbe4d609 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 2 Apr 2012 17:46:02 -0400 Subject: [PATCH 2/2] add vars_prompt to playbooks - this allows some vars to be prompted for at the start of the playbook setup - defaults to no output since this would mostly be used for passwords --- lib/ansible/callbacks.py | 7 +++++++ lib/ansible/playbook.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index fe2c8f4b1bd..731d244718e 100755 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -20,6 +20,7 @@ import utils import sys +import getpass ####################################################### @@ -176,6 +177,12 @@ class PlaybookCallbacks(object): def on_task_start(self, name, is_conditional): print utils.task_start_msg(name, is_conditional) + def on_vars_prompt(self, varname, private=True): + msg = 'input for %s: ' % varname + if private: + return getpass.getpass(msg) + return raw_input(msg) + def on_setup_primary(self): print "SETUP PHASE ****************************\n" diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index 5af26f42429..1cd9a5b5474 100755 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -95,6 +95,13 @@ class PlayBook(object): vars = play.get('vars', {}) if type(vars) != dict: raise errors.AnsibleError("'vars' section must contain only key/value pairs") + vars_prompt = play.get('vars_prompt', {}) + if type(vars_prompt) != dict: + raise errors.AnsibleError("'vars_prompt' section must contain only key/value pairs") + for vname in vars_prompt: + print vars_prompt[vname] + # FIXME - need some way to know that this prompt should be getpass or raw_input + vars[vname] = self.callbacks.on_vars_prompt(vname) return vars # *****************************************************