From 191347676eea08817da3fb237f24cdbf2d16e307 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Fri, 4 Dec 2015 09:18:45 -0800 Subject: [PATCH] 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 #2619 --- web_infrastructure/htpasswd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web_infrastructure/htpasswd.py b/web_infrastructure/htpasswd.py index 4253f1572ac..83a6445374b 100644 --- a/web_infrastructure/htpasswd.py +++ b/web_infrastructure/htpasswd.py @@ -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)