diff options
author | Matt Martz <matt@sivel.net> | 2016-03-08 21:03:05 -0600 |
---|---|---|
committer | Matt Martz <matt@sivel.net> | 2016-03-08 21:03:05 -0600 |
commit | 27b28e78b2cb5e10be9a48ce665aa40d4a21c10a (patch) | |
tree | a03e53954028381bd65670cb20c1142f4fbb6932 /commands | |
parent | 767dd4bdc6d2e382787c412c6d52f2b9470783a9 (diff) | |
download | ansible-modules-extras-27b28e78b2cb5e10be9a48ce665aa40d4a21c10a.tar.gz |
Catch errors related to insufficient (old) versions of pexpect. Fixes #13660
Diffstat (limited to 'commands')
-rw-r--r-- | commands/expect.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/commands/expect.py b/commands/expect.py index 5a7d7dba..45921794 100644 --- a/commands/expect.py +++ b/commands/expect.py @@ -188,8 +188,23 @@ def main(): startd = datetime.datetime.now() try: - out, rc = pexpect.runu(args, timeout=timeout, withexitstatus=True, - events=events, cwd=chdir, echo=echo) + try: + # Prefer pexpect.run from pexpect>=4 + out, rc = pexpect.run(args, timeout=timeout, withexitstatus=True, + events=events, cwd=chdir, echo=echo, + encoding='utf-8') + except TypeError: + # Use pexpect.runu in pexpect>=3.3,<4 + out, rc = pexpect.runu(args, timeout=timeout, withexitstatus=True, + events=events, cwd=chdir, echo=echo) + except (TypeError, AttributeError), e: + # This should catch all insufficient versions of pexpect + # We deem them insufficient for their lack of ability to specify + # to not echo responses via the run/runu functions, which would + # potentially leak sensentive information + module.fail_json(msg='Insufficient version of pexpect installed ' + '(%s), this module requires pexpect>=3.3. ' + 'Error was %s' % (pexpect.__version__, e)) except pexpect.ExceptionPexpect, e: module.fail_json(msg='%s' % e) |