When the password file does not exist and we're making sure the user isn't in the password file, change error into a warning

Warning catches typos in the filename.  Since the playbook is saying
"make sure this user doesn't have an entry" it makes more sense to warn
than to error.

Fixes 
This commit is contained in:
Toshio Kuratomi 2015-12-04 09:18:45 -08:00
parent a1ea2182b7
commit 191347676e

View file

@ -97,6 +97,7 @@ else:
apache_hashes = ["apr_md5_crypt", "des_crypt", "ldap_sha1", "plaintext"]
def create_missing_directories(dest):
destpath = os.path.dirname(dest)
if not os.path.exists(destpath):
@ -155,9 +156,6 @@ def absent(dest, username, check_mode):
""" Ensures user is absent
Returns (msg, changed) """
if not os.path.exists(dest):
raise ValueError("%s does not exists" % dest)
if StrictVersion(passlib.__version__) >= StrictVersion('1.6'):
ht = HtpasswdFile(dest, new=False)
else:
@ -244,6 +242,9 @@ def main():
if state == 'present':
(msg, changed) = present(path, username, password, crypt_scheme, create, check_mode)
elif state == 'absent':
if not os.path.exists(path):
module.exit_json(msg="%s not present" % username,
warnings="%s does not exist" % path, changed=False)
(msg, changed) = absent(path, username, check_mode)
else:
module.fail_json(msg="Invalid state: %s" % state)