| 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": ["deprecated"], |
| 14 |
"supported_by": "community", |
| 15 |
} |
| 16 |
|
| 17 |
DOCUMENTATION = r""" |
| 18 |
--- |
| 19 |
module: purefa_sso |
| 20 |
version_added: '1.9.0' |
| 21 |
deprecated: |
| 22 |
removed_in: '2.0.0' |
| 23 |
why: Superseded by M(purestorage.flasharray.purefa_admin) |
| 24 |
alternative: Use M(purestorage.flasharray.purefa_admin) instead. |
| 25 |
short_description: Configure Pure Storage FlashArray Single Sign-On |
| 26 |
description: |
| 27 |
- Enable or disable Single Sign-On (SSO) to give LDAP users the ability |
| 28 |
to navigate seamlessly from Pure1 Manage to the current array through a |
| 29 |
single login. |
| 30 |
author: |
| 31 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 32 |
options: |
| 33 |
state: |
| 34 |
description: |
| 35 |
- Enable or disable the array Single Sign-On from Pure1 Manage |
| 36 |
default: present |
| 37 |
type: str |
| 38 |
choices: [ present, absent ] |
| 39 |
extends_documentation_fragment: |
| 40 |
- purestorage.flasharray.purestorage.fa |
| 41 |
""" |
| 42 |
|
| 43 |
EXAMPLES = r""" |
| 44 |
- name: Enable SSO |
| 45 |
purestorage.flasharray.purefa_sso: |
| 46 |
state: present |
| 47 |
fa_url: 10.10.10.2 |
| 48 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 49 |
|
| 50 |
- name: Disable SSO |
| 51 |
purestorage.flasharray.purefa_sso: |
| 52 |
state: absent |
| 53 |
fa_url: 10.10.10.2 |
| 54 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 55 |
""" |
| 56 |
|
| 57 |
RETURN = r""" |
| 58 |
""" |
| 59 |
|
| 60 |
HAS_PURESTORAGE = True |
| 61 |
try: |
| 62 |
from pypureclient.flasharray import AdminSettings |
| 63 |
except ImportError: |
| 64 |
HAS_PURESTORAGE = False |
| 65 |
|
| 66 |
|
| 67 |
from ansible.module_utils.basic import AnsibleModule |
| 68 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 69 |
get_array, |
| 70 |
purefa_argument_spec, |
| 71 |
) |
| 72 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 73 |
LooseVersion, |
| 74 |
) |
| 75 |
|
| 76 |
SSO_API_VERSION = "2.2" |
| 77 |
|
| 78 |
|
| 79 |
def main(): |
| 80 |
argument_spec = purefa_argument_spec() |
| 81 |
argument_spec.update( |
| 82 |
dict( |
| 83 |
state=dict(type="str", default="present", choices=["present", "absent"]), |
| 84 |
) |
| 85 |
) |
| 86 |
|
| 87 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 88 |
|
| 89 |
if not HAS_PURESTORAGE: |
| 90 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 91 |
|
| 92 |
state = module.params["state"] |
| 93 |
array = get_array(module) |
| 94 |
api_version = array.get_rest_version() |
| 95 |
changed = False |
| 96 |
if LooseVersion(SSO_API_VERSION) <= LooseVersion(api_version): |
| 97 |
current_sso = list(array.get_admins_settings().items)[0].single_sign_on_enabled |
| 98 |
if (state == "present" and not current_sso) or ( |
| 99 |
state == "absent" and current_sso |
| 100 |
): |
| 101 |
changed = True |
| 102 |
if not module.check_mode: |
| 103 |
res = array.patch_admins_settings( |
| 104 |
admin_settings=AdminSettings( |
| 105 |
single_sign_on_enabled=bool(state == "present") |
| 106 |
) |
| 107 |
) |
| 108 |
if res.status_code != 200: |
| 109 |
module.fail_json( |
| 110 |
msg="Failed to change Single Sign-On status. Error: {0}".format( |
| 111 |
res.errors[0].message |
| 112 |
) |
| 113 |
) |
| 114 |
else: |
| 115 |
module.fail_json(msg="Purity version does not support Single Sign-On") |
| 116 |
module.exit_json(changed=changed) |
| 117 |
|
| 118 |
|
| 119 |
if __name__ == "__main__": |
| 120 |
main() |