summaryrefslogtreecommitdiff
path: root/lib/ansible/utils
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2020-03-27 22:09:51 -0400
committerMatt Clay <matt@mystile.com>2020-04-14 17:06:15 -0700
commit52d509717e64bfe85f058764abc1d2e5e21bf046 (patch)
tree204bc8901ce79ea57a6b2518f55b4c4a304541ca /lib/ansible/utils
parent8088ffb853bcd9c6760c61f8b12cb321ac3c60c4 (diff)
downloadansible-52d509717e64bfe85f058764abc1d2e5e21bf046.tar.gz
fallback to uid when no uname (#68466)
* fallback to uid when no uname fixes #68007 Co-Authored-By: Matt Clay <matt@mystile.com> (cherry picked from commit 1570098e86d3dc8dc38a23b65001cf232b664bf6)
Diffstat (limited to 'lib/ansible/utils')
-rw-r--r--lib/ansible/utils/display.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py
index a24d2cd0d7..6d47f5f506 100644
--- a/lib/ansible/utils/display.py
+++ b/lib/ansible/utils/display.py
@@ -62,7 +62,12 @@ class FilterUserInjector(logging.Filter):
This is a filter which injects the current user as the 'user' attribute on each record. We need to add this filter
to all logger handlers so that 3rd party libraries won't print an exception due to user not being defined.
"""
- username = getpass.getuser()
+
+ try:
+ username = getpass.getuser()
+ except KeyError:
+ # people like to make containers w/o actual valid passwd/shadow and use host uids
+ username = 'uid=%s' % os.getuid()
def filter(self, record):
record.user = FilterUserInjector.username