summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-08-22 22:40:52 -0400
committerScott Moser <smoser@ubuntu.com>2012-08-22 22:40:52 -0400
commit700cb1a5d568dae2ecc8a9620874cebca97536a5 (patch)
tree26db43f53365c6a3afdc41b70305ae8581755891 /cloudinit/distros
parentfc8f46d5f49c29d234560749bdf9789812571327 (diff)
downloadvyos-cloud-init-700cb1a5d568dae2ecc8a9620874cebca97536a5.tar.gz
vyos-cloud-init-700cb1a5d568dae2ecc8a9620874cebca97536a5.zip
do not attempt the useradd command if user exists
Previously we were only logging that the user existed and then still trying to run the command (which would raise error) As a result, none of the rest of the things would be done (sshimport id and such)
Diffstat (limited to 'cloudinit/distros')
-rw-r--r--cloudinit/distros/__init__.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 669dca18..686c6a9b 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -211,11 +211,6 @@ class Distro(object):
distros where useradd is not desirable or not available.
"""
- if self.isuser(name):
- LOG.warn("User %s already exists, skipping." % name)
- else:
- LOG.debug("Creating name %s" % name)
-
adduser_cmd = ['useradd', name]
x_adduser_cmd = ['useradd', name]
@@ -263,11 +258,15 @@ class Distro(object):
adduser_cmd.append('-m')
# Create the user
- try:
- util.subp(adduser_cmd, logstring=x_adduser_cmd)
- except Exception as e:
- util.logexc(LOG, "Failed to create user %s due to error.", e)
- raise e
+ if self.isuser(name):
+ LOG.warn("User %s already exists, skipping." % name)
+ else:
+ LOG.debug("Creating name %s" % name)
+ try:
+ util.subp(adduser_cmd, logstring=x_adduser_cmd)
+ except Exception as e:
+ util.logexc(LOG, "Failed to create user %s due to error.", e)
+ raise e
# Set password if plain-text password provided
if 'plain_text_passwd' in kwargs and kwargs['plain_text_passwd']: