summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/fragments/local_bad_user.yml2
-rw-r--r--lib/ansible/plugins/connection/local.py10
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 '''