fix user module error when generating ssh keys w/o a home (#29055)

* Fixes https://github.com/ansible/ansible/issues/29028

* raise Exception when no home directory
This commit is contained in:
Job Evers‐Meltzer 2018-04-13 16:22:53 -04:00 committed by Brian Coca
parent c1e4ef39cb
commit 636e705260

View file

@ -619,14 +619,18 @@ class User(object):
if os.path.isabs(self.ssh_file):
ssh_key_file = self.ssh_file
else:
if not os.path.exists(info[5]) and not self.module.check_mode:
raise Exception('User %s home directory does not exist' % self.name)
ssh_key_file = os.path.join(info[5], self.ssh_file)
return ssh_key_file
def ssh_key_gen(self):
info = self.user_info()
if not os.path.exists(info[5]) and not self.module.check_mode:
return (1, '', 'User %s home directory does not exist' % self.name)
ssh_key_file = self.get_ssh_key_path()
try:
ssh_key_file = self.get_ssh_key_path()
except Exception:
e = get_exception()
return (1, '', str(e))
ssh_dir = os.path.dirname(ssh_key_file)
if not os.path.exists(ssh_dir):
if self.module.check_mode: