Last active
July 30, 2019 20:53
-
-
Save s-hertel/881ab33ac78371b5e3bd4b69b64c5338 to your computer and use it in GitHub Desktop.
Fix iam_password_policy when no max pw age
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git diff | |
diff --git a/lib/ansible/modules/cloud/amazon/iam_password_policy.py b/lib/ansible/modules/cloud/amazon/iam_password_policy.py | |
index 435cf08605..dcef27923e 100644 | |
--- a/lib/ansible/modules/cloud/amazon/iam_password_policy.py | |
+++ b/lib/ansible/modules/cloud/amazon/iam_password_policy.py | |
@@ -127,18 +127,21 @@ class IAMConnection(object): | |
pw_reuse_prevent = module.params.get('pw_reuse_prevent') | |
pw_expire = module.params.get('pw_expire') | |
+ update_parameters = dict( | |
+ MinimumPasswordLength=min_pw_length, | |
+ RequireSymbols=require_symbols, | |
+ RequireNumbers=require_numbers, | |
+ RequireUppercaseCharacters=require_uppercase, | |
+ RequireLowercaseCharacters=require_lowercase, | |
+ AllowUsersToChangePassword=allow_pw_change, | |
+ PasswordReusePrevention=pw_reuse_prevent, | |
+ HardExpiry=pw_expire | |
+ ) | |
+ if pw_max_age: | |
+ update_parameters.update(MaxPasswordAge=pw_max_age) | |
+ | |
try: | |
- results = policy.update( | |
- MinimumPasswordLength=min_pw_length, | |
- RequireSymbols=require_symbols, | |
- RequireNumbers=require_numbers, | |
- RequireUppercaseCharacters=require_uppercase, | |
- RequireLowercaseCharacters=require_lowercase, | |
- AllowUsersToChangePassword=allow_pw_change, | |
- MaxPasswordAge=pw_max_age, | |
- PasswordReusePrevention=pw_reuse_prevent, | |
- HardExpiry=pw_expire | |
- ) | |
+ results = policy.update(**update_parameters) | |
policy.reload() | |
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: | |
self.module.fail_json_aws(e, msg="Couldn't update IAM Password Policy") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment