diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2015-08-06 19:19:46 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2015-08-06 19:20:45 -0400 |
commit | a555a0652eaf489b98ae5ad28003b7c31c7aa63e (patch) | |
tree | 4c8be90ac661baf2936d80a56329c39d7bba39c5 /lib/ansible/executor/playbook_executor.py | |
parent | ce52fdebe895003768e243228c895aae65fede98 (diff) | |
download | ansible-a555a0652eaf489b98ae5ad28003b7c31c7aa63e.tar.gz |
allow for vars_prompt and pause prompt to be skipped in non interactive settings
ansible-pull users rejoice
Diffstat (limited to 'lib/ansible/executor/playbook_executor.py')
-rw-r--r-- | lib/ansible/executor/playbook_executor.py | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 686da5c321..96833d5c17 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -238,34 +238,38 @@ class PlaybookExecutor: def _do_var_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None): - if prompt and default is not None: - msg = "%s [%s]: " % (prompt, default) - elif prompt: - msg = "%s: " % prompt - else: - msg = 'input for %s: ' % varname - - def do_prompt(prompt, private): - if sys.stdout.encoding: - msg = prompt.encode(sys.stdout.encoding) + if sys.__stdin__.isatty(): + if prompt and default is not None: + msg = "%s [%s]: " % (prompt, default) + elif prompt: + msg = "%s: " % prompt + else: + msg = 'input for %s: ' % varname + + def do_prompt(prompt, private): + if sys.stdout.encoding: + msg = prompt.encode(sys.stdout.encoding) + else: + # when piping the output, or at other times when stdout + # may not be the standard file descriptor, the stdout + # encoding may not be set, so default to something sane + msg = prompt.encode(locale.getpreferredencoding()) + if private: + return getpass.getpass(msg) + return raw_input(msg) + + if confirm: + while True: + result = do_prompt(msg, private) + second = do_prompt("confirm " + msg, private) + if result == second: + break + self._display.display("***** VALUES ENTERED DO NOT MATCH ****") else: - # when piping the output, or at other times when stdout - # may not be the standard file descriptor, the stdout - # encoding may not be set, so default to something sane - msg = prompt.encode(locale.getpreferredencoding()) - if private: - return getpass.getpass(msg) - return raw_input(msg) - - if confirm: - while True: result = do_prompt(msg, private) - second = do_prompt("confirm " + msg, private) - if result == second: - break - self._display.display("***** VALUES ENTERED DO NOT MATCH ****") else: - result = do_prompt(msg, private) + result = None + self._display.warning("Not prompting as we are not in interactive mode") # if result is false and default is not None if not result and default is not None: |