def audit_user(user, audit_output=None): """ Logs on provided hosts and runs id for the supplied user with sudo. Output is logged to the provided file argument or a default using the python gettempdir() function and the following file name format: /tmp/audit-user-{user}.csv The contents of this file are host,user,command output Note that if the file already exists, output will be appended to the existing file. """ logging.info("Auditing {host}.".format(host=env.host_string)) if not audit_output: audit_output = tempfile.gettempdir() + "/audit-user-{user}.csv".format( user=user) with settings(warn_only=True): with open(audit_output, 'a') as audit: output = noopable(sudo)("id {user}".format(user=user)) audit.write("{host},{user},{output}\n".format( host=env.host_string, user=user, output=output ) )
def audit_user(user, audit_output=None): """ Logs on provided hosts and runs id for the supplied user with sudo. Output is logged to the provided file argument or a default using the python gettempdir() function and the following file name format: /tmp/audit-user-{user}.csv The contents of this file are host,user,command output Note that if the file already exists, output will be appended to the existing file. """ logging.info("Auditing {host}.".format(host=env.host_string)) if not audit_output: audit_output = tempfile.gettempdir() + "/audit-user-{user}.csv".format(user=user) with settings(warn_only=True): with open(audit_output, "a") as audit: output = noopable(sudo)("id {user}".format(user=user)) audit.write("{host},{user},{output}\n".format(host=env.host_string, user=user, output=output))
def remove_user(user): """ Logs on to provided hosts and runs userdel for the supplied user with sudo. The user's home directory is preserved. """ logging.info("Removing {user} user from {host}.".format(user=user, host=env.host_string)) with settings(warn_only=True): output = noopable(sudo)("userdel {user}".format(user=user)) logging.info("Output of userdel command on host {host} was {out}".format(host=env.host_string, out=output))
def remove_user(user): """ Logs on to provided hosts and runs userdel for the supplied user with sudo. The user's home directory is preserved. """ logging.info("Removing {user} user from {host}.".format( user=user,host=env.host_string)) with settings(warn_only=True): output = noopable(sudo)("userdel {user}".format(user=user)) logging.info("Output of userdel command on host {host} was {out}".format( host=env.host_string,out=output ) )