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
pull/56508/merge
Brian Coca 2 years ago committed by GitHub
parent 38fe34244c
commit 5f3a6b78db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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).

@ -18,12 +18,12 @@ DOCUMENTATION = '''
- The remote user is ignored, the user with which the ansible CLI was executed is used instead. - The remote user is ignored, the user with which the ansible CLI was executed is used instead.
''' '''
import fcntl
import getpass
import os import os
import pty import pty
import shutil import shutil
import subprocess import subprocess
import fcntl
import getpass
import ansible.constants as C import ansible.constants as C
from ansible.errors import AnsibleError, AnsibleFileNotFound from ansible.errors import AnsibleError, AnsibleFileNotFound
@ -47,7 +47,11 @@ class Connection(ConnectionBase):
super(Connection, self).__init__(*args, **kwargs) super(Connection, self).__init__(*args, **kwargs)
self.cwd = None self.cwd = None
try:
self.default_user = getpass.getuser() 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): def _connect(self):
''' connect to the local host; nothing to do here ''' ''' connect to the local host; nothing to do here '''

Loading…
Cancel
Save