| 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: purefa_admin |
| 20 |
version_added: '1.12.0' |
| 21 |
short_description: Configure Pure Storage FlashArray Global Admin settings |
| 22 |
description: |
| 23 |
- Set global admin settings for the FlashArray |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
sso: |
| 28 |
description: |
| 29 |
- Enable or disable the array Single Sign-On from Pure1 Manage |
| 30 |
default: false |
| 31 |
type: bool |
| 32 |
max_login: |
| 33 |
description: |
| 34 |
- Maximum number of failed logins before account is locked |
| 35 |
type: int |
| 36 |
min_password: |
| 37 |
description: |
| 38 |
- Minimum user password length |
| 39 |
default: 1 |
| 40 |
type: int |
| 41 |
lockout: |
| 42 |
description: |
| 43 |
- Account lockout duration, in seconds, after max_login exceeded |
| 44 |
- Range between 1 second and 90 days (7776000 seconds) |
| 45 |
type: int |
| 46 |
extends_documentation_fragment: |
| 47 |
- purestorage.flasharray.purestorage.fa |
| 48 |
""" |
| 49 |
|
| 50 |
EXAMPLES = r""" |
| 51 |
- name: Set global login parameters |
| 52 |
purestorage.flasharray.purefa_admin: |
| 53 |
sso: false |
| 54 |
max_login: 5 |
| 55 |
min_password: 10 |
| 56 |
lockout: 300 |
| 57 |
fa_url: 10.10.10.2 |
| 58 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 59 |
""" |
| 60 |
|
| 61 |
RETURN = r""" |
| 62 |
""" |
| 63 |
|
| 64 |
HAS_PURESTORAGE = True |
| 65 |
try: |
| 66 |
from pypureclient.flasharray import AdminSettings |
| 67 |
except ImportError: |
| 68 |
HAS_PURESTORAGE = False |
| 69 |
|
| 70 |
|
| 71 |
from ansible.module_utils.basic import AnsibleModule |
| 72 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 73 |
get_array, |
| 74 |
purefa_argument_spec, |
| 75 |
) |
| 76 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 77 |
LooseVersion, |
| 78 |
) |
| 79 |
|
| 80 |
MIN_API_VERSION = "2.2" |
| 81 |
|
| 82 |
|
| 83 |
def main(): |
| 84 |
argument_spec = purefa_argument_spec() |
| 85 |
argument_spec.update( |
| 86 |
dict( |
| 87 |
sso=dict(type="bool", default=False), |
| 88 |
max_login=dict(type="int"), |
| 89 |
min_password=dict(type="int", default=1, no_log=False), |
| 90 |
lockout=dict(type="int"), |
| 91 |
) |
| 92 |
) |
| 93 |
|
| 94 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 95 |
|
| 96 |
if not HAS_PURESTORAGE: |
| 97 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 98 |
if module.params["lockout"] and not 1 <= module.params["lockout"] <= 7776000: |
| 99 |
module.fail_json(msg="Lockout must be between 1 and 7776000 seconds") |
| 100 |
array = get_array(module) |
| 101 |
api_version = array.get_rest_version() |
| 102 |
changed = False |
| 103 |
if LooseVersion(MIN_API_VERSION) <= LooseVersion(api_version): |
| 104 |
current_settings = list(array.get_admins_settings().items)[0] |
| 105 |
if ( |
| 106 |
module.params["sso"] |
| 107 |
and module.params["sso"] != current_settings.single_sign_on_enabled |
| 108 |
): |
| 109 |
changed = True |
| 110 |
sso = module.params["sso"] |
| 111 |
else: |
| 112 |
sso = current_settings.single_sign_on_enabled |
| 113 |
if ( |
| 114 |
module.params["min_password"] |
| 115 |
and module.params["min_password"] != current_settings.min_password_length |
| 116 |
): |
| 117 |
changed = True |
| 118 |
min_password = module.params["min_password"] |
| 119 |
else: |
| 120 |
min_password = current_settings.min_password_length |
| 121 |
lockout = getattr(current_settings, "lockout_duration", None) |
| 122 |
if ( |
| 123 |
lockout |
| 124 |
and module.params["lockout"] |
| 125 |
and lockout != module.params["lockout"] * 1000 |
| 126 |
): |
| 127 |
changed = True |
| 128 |
lockout = module.params["lockout"] * 1000 |
| 129 |
elif not lockout and module.params["lockout"]: |
| 130 |
changed = True |
| 131 |
lockout = module.params["lockout"] * 1000 |
| 132 |
max_login = getattr(current_settings, "max_login_attempts", None) |
| 133 |
if ( |
| 134 |
max_login |
| 135 |
and module.params["max_login"] |
| 136 |
and max_login != module.params["max_login"] |
| 137 |
): |
| 138 |
changed = True |
| 139 |
max_login = module.params["max_login"] |
| 140 |
elif not max_login and module.params["max_login"]: |
| 141 |
changed = True |
| 142 |
max_login = module.params["max_login"] |
| 143 |
if changed and not module.check_mode: |
| 144 |
if max_login: |
| 145 |
admin = AdminSettings( |
| 146 |
single_sign_on_enabled=sso, |
| 147 |
min_password_length=min_password, |
| 148 |
max_login_attempts=max_login, |
| 149 |
) |
| 150 |
if lockout: |
| 151 |
admin = AdminSettings( |
| 152 |
single_sign_on_enabled=sso, |
| 153 |
min_password_length=min_password, |
| 154 |
lockout_duration=lockout, |
| 155 |
) |
| 156 |
if lockout and max_login: |
| 157 |
admin = AdminSettings( |
| 158 |
single_sign_on_enabled=sso, |
| 159 |
min_password_length=min_password, |
| 160 |
lockout_duration=lockout, |
| 161 |
max_login_attempts=max_login, |
| 162 |
) |
| 163 |
if not lockout and not max_login: |
| 164 |
admin = AdminSettings( |
| 165 |
single_sign_on_enabled=sso, |
| 166 |
min_password_length=min_password, |
| 167 |
) |
| 168 |
res = array.patch_admins_settings(admin_settings=admin) |
| 169 |
if res.status_code != 200: |
| 170 |
module.fail_json( |
| 171 |
msg="Failed to change Global Admin settings. Error: {0}".format( |
| 172 |
res.errors[0].message |
| 173 |
) |
| 174 |
) |
| 175 |
else: |
| 176 |
module.fail_json(msg="Purity version does not support Global Admin settings") |
| 177 |
module.exit_json(changed=changed) |
| 178 |
|
| 179 |
|
| 180 |
if __name__ == "__main__": |
| 181 |
main() |