From 700cb1a5d568dae2ecc8a9620874cebca97536a5 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 22 Aug 2012 22:40:52 -0400 Subject: 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) --- cloudinit/distros/__init__.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'cloudinit/distros') 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']: -- cgit v1.2.3