diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2022-12-06 17:09:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 14:09:46 -0800 |
commit | fc2670772a44fd51dcfa81034d2ae0e9ecabecd8 (patch) | |
tree | 4376ca9c800e2db9e8cc7ad315e1bebb175162e9 | |
parent | 5e2806b5029b3e92de860834d93904e2e095455d (diff) | |
download | ansible-fc2670772a44fd51dcfa81034d2ae0e9ecabecd8.tar.gz |
local connection: avoid tb when running in container with invalid user (#79414) (#79503)
* 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
(cherry picked from commit 5f3a6b78db093f8d1b062bbd70ac6bf375fdca04)
-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 ''' |