diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2022-11-29 10:08:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-29 16:08:32 +0100 |
commit | 5f3a6b78db093f8d1b062bbd70ac6bf375fdca04 (patch) | |
tree | b300539aa9c2dd334626214dd79f35896b12a1d7 | |
parent | 38fe34244ca166418a882cc6e191ccff3a8fc9d1 (diff) | |
download | ansible-5f3a6b78db093f8d1b062bbd70ac6bf375fdca04.tar.gz |
local connection: avoid tb when running in container with invalid user (#79414)
* local connection: avoid tb when running in container with invalid user
* clog
* cannot use uid, leave empty and ~/ will resolve itself
* get back to what it did
-rw-r--r-- | changelogs/fragments/local_bad_user.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/connection/local.py | 10 |
2 files changed, 9 insertions, 3 deletions
diff --git a/changelogs/fragments/local_bad_user.yml b/changelogs/fragments/local_bad_user.yml new file mode 100644 index 0000000000..af336a63f9 --- /dev/null +++ b/changelogs/fragments/local_bad_user.yml @@ -0,0 +1,2 @@ +bugfixes: + - connection local now avoids traceback on invalid user being used to execuet ansible (valid in host, but not in container). diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py index 182e21cd7d..27afd105c8 100644 --- a/lib/ansible/plugins/connection/local.py +++ b/lib/ansible/plugins/connection/local.py @@ -18,12 +18,12 @@ DOCUMENTATION = ''' - The remote user is ignored, the user with which the ansible CLI was executed is used instead. ''' +import fcntl +import getpass import os import pty import shutil import subprocess -import fcntl -import getpass import ansible.constants as C from ansible.errors import AnsibleError, AnsibleFileNotFound @@ -47,7 +47,11 @@ class Connection(ConnectionBase): super(Connection, self).__init__(*args, **kwargs) self.cwd = None - self.default_user = getpass.getuser() + try: + self.default_user = getpass.getuser() + except KeyError: + display.vv("Current user (uid=%s) does not seem to exist on this system, leaving user empty." % os.getuid()) + self.default_user = "" def _connect(self): ''' connect to the local host; nothing to do here ''' |