diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2017-04-18 11:39:49 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2017-04-18 11:42:36 -0400 |
commit | 3e9d4607ce2bb25ad2784cef218c732352f2cb1f (patch) | |
tree | 454e694f0ac3584e2fb78b5d803434ba1a97a9ea | |
parent | 39ce8c6610ecaa1a5f992f76d4f868b2cce8fd39 (diff) | |
download | ansible-3e9d4607ce2bb25ad2784cef218c732352f2cb1f.tar.gz |
tolerate 'batch' systems that mess with stdin (#23596)
* tolerate 'batch' systems taht mess with stdin
fixes #23541
* have pause on windows tolerate devnull
* tuplie
(cherry picked from commit 586fcae3981ce3d4c805051338ac6bd2df9a95c6)
-rw-r--r-- | lib/ansible/executor/process/worker.py | 34 | ||||
-rw-r--r-- | lib/ansible/plugins/action/pause.py | 5 |
2 files changed, 22 insertions, 17 deletions
diff --git a/lib/ansible/executor/process/worker.py b/lib/ansible/executor/process/worker.py index d1bc56f637..db6fd5d9cf 100644 --- a/lib/ansible/executor/process/worker.py +++ b/lib/ansible/executor/process/worker.py @@ -77,21 +77,25 @@ class WorkerProcess(multiprocessing.Process): self._variable_manager = variable_manager self._shared_loader_obj = shared_loader_obj - # dupe stdin, if we have one - self._new_stdin = sys.stdin - try: - fileno = sys.stdin.fileno() - if fileno is not None: - try: - self._new_stdin = os.fdopen(os.dup(fileno)) - except OSError: - # couldn't dupe stdin, most likely because it's - # not a valid file descriptor, so we just rely on - # using the one that was passed in - pass - except ValueError: - # couldn't get stdin's fileno, so we just carry on - pass + if sys.stdin.isatty(): + # dupe stdin, if we have one + self._new_stdin = sys.stdin + try: + fileno = sys.stdin.fileno() + if fileno is not None: + try: + self._new_stdin = os.fdopen(os.dup(fileno)) + except OSError: + # couldn't dupe stdin, most likely because it's + # not a valid file descriptor, so we just rely on + # using the one that was passed in + pass + except (AttributeError, ValueError): + # couldn't get stdin's fileno, so we just carry on + pass + else: + # set to /dev/null + self._new_stdin = os.devnull def run(self): ''' diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py index afe4f1d34b..7f324b7284 100644 --- a/lib/ansible/plugins/action/pause.py +++ b/lib/ansible/plugins/action/pause.py @@ -123,8 +123,9 @@ class ActionModule(ActionBase): fd = None try: fd = self._connection._new_stdin.fileno() - except ValueError: - # someone is using a closed file descriptor as stdin + except (ValueError, AttributeError): + # ValueError: someone is using a closed file descriptor as stdin + # AttributeError: someone is using a null file descriptor as stdin on windoez pass if fd is not None: if isatty(fd): |