| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = { |
| 12 |
"metadata_version": "1.1", |
| 13 |
"status": ["preview"], |
| 14 |
"supported_by": "community", |
| 15 |
} |
| 16 |
|
| 17 |
DOCUMENTATION = r""" |
| 18 |
--- |
| 19 |
module: purefb_admin |
| 20 |
version_added: '1.8.0' |
| 21 |
short_description: Configure Pure Storage FlashBlade Global Admin settings |
| 22 |
description: |
| 23 |
- Set global admin settings for the FlashBlade |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
max_login: |
| 28 |
description: |
| 29 |
- Maximum number of failed logins before account is locked |
| 30 |
type: int |
| 31 |
min_password: |
| 32 |
description: |
| 33 |
- Minimum user password length |
| 34 |
- Range between 1 and 100 |
| 35 |
default: 1 |
| 36 |
type: int |
| 37 |
lockout: |
| 38 |
description: |
| 39 |
- Account lockout duration, in seconds, after max_login exceeded |
| 40 |
- Range between 1 second and 90 days (7776000 seconds) |
| 41 |
type: int |
| 42 |
extends_documentation_fragment: |
| 43 |
- purestorage.flashblade.purestorage.fb |
| 44 |
""" |
| 45 |
|
| 46 |
EXAMPLES = r""" |
| 47 |
- name: Set global login parameters |
| 48 |
purestorage.flashblade.purefb_admin: |
| 49 |
max_login: 5 |
| 50 |
min_password: 10 |
| 51 |
lockout: 300 |
| 52 |
fb_url: 10.10.10.2 |
| 53 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 54 |
""" |
| 55 |
|
| 56 |
RETURN = r""" |
| 57 |
""" |
| 58 |
|
| 59 |
HAS_PURESTORAGE = True |
| 60 |
try: |
| 61 |
from pypureclient.flashblade import AdminSetting |
| 62 |
except ImportError: |
| 63 |
HAS_PURESTORAGE = False |
| 64 |
|
| 65 |
|
| 66 |
from ansible.module_utils.basic import AnsibleModule |
| 67 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 68 |
get_system, |
| 69 |
purefb_argument_spec, |
| 70 |
) |
| 71 |
|
| 72 |
|
| 73 |
def main(): |
| 74 |
argument_spec = purefb_argument_spec() |
| 75 |
argument_spec.update( |
| 76 |
dict( |
| 77 |
max_login=dict(type="int"), |
| 78 |
min_password=dict(type="int", default=1, no_log=False), |
| 79 |
lockout=dict(type="int"), |
| 80 |
) |
| 81 |
) |
| 82 |
|
| 83 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 84 |
|
| 85 |
if not HAS_PURESTORAGE: |
| 86 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 87 |
if module.params["lockout"] and not 1 <= module.params["lockout"] <= 7776000: |
| 88 |
module.fail_json(msg="Lockout must be between 1 and 7776000 seconds") |
| 89 |
if not 1 <= module.params["min_password"] <= 100: |
| 90 |
module.fail_json(msg="Minimum password length must be between 1 and 100") |
| 91 |
blade = get_system(module) |
| 92 |
api_version = list(blade.get_versions().items) |
| 93 |
changed = False |
| 94 |
current_settings = list(blade.get_admins_settings().items)[0] |
| 95 |
lockout = getattr(current_settings, "lockout_duration", None) |
| 96 |
max_login = getattr(current_settings, "max_login_attempts", None) |
| 97 |
min_password = getattr(current_settings, "min_password_length", 1) |
| 98 |
if min_password != module.params["min_password"]: |
| 99 |
changed = True |
| 100 |
min_password = module.params["min_password"] |
| 101 |
if lockout and lockout != module.params["lockout"] * 1000: |
| 102 |
changed = True |
| 103 |
lockout = module.params["lockout"] * 1000 |
| 104 |
elif not lockout and module.params["lockout"]: |
| 105 |
changed = True |
| 106 |
lockout = module.params["lockout"] * 1000 |
| 107 |
if max_login and max_login != module.params["max_login"]: |
| 108 |
changed = True |
| 109 |
max_login = module.params["max_login"] |
| 110 |
elif not max_login and module.params["max_login"]: |
| 111 |
changed = True |
| 112 |
max_login = module.params["max_login"] |
| 113 |
|
| 114 |
if changed and not module.check_mode: |
| 115 |
admin = AdminSetting( |
| 116 |
min_password_length=min_password, |
| 117 |
max_login_attempts=max_login, |
| 118 |
lockout_duration=lockout, |
| 119 |
) |
| 120 |
|
| 121 |
res = blade.patch_admins_settings(admin_setting=admin) |
| 122 |
if res.status_code != 200: |
| 123 |
module.fail_json( |
| 124 |
msg="Failed to change Global Admin settings. Error: {0}".format( |
| 125 |
res.errors[0].message |
| 126 |
) |
| 127 |
) |
| 128 |
module.exit_json(changed=changed) |
| 129 |
|
| 130 |
|
| 131 |
if __name__ == "__main__": |
| 132 |
main() |