| 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_eula |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Sign Pure Storage FlashArray EULA |
| 22 |
description: |
| 23 |
- Sign the FlashArray EULA for Day 0 config, or change signatory. |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
company: |
| 28 |
description: |
| 29 |
- Full legal name of the entity. |
| 30 |
- The value must be between 1 and 64 characters in length. |
| 31 |
type: str |
| 32 |
name: |
| 33 |
description: |
| 34 |
- Full legal name of the individual at the company who has the authority to accept the terms of the agreement. |
| 35 |
- The value must be between 1 and 64 characters in length. |
| 36 |
type: str |
| 37 |
title: |
| 38 |
description: |
| 39 |
- Individual's job title at the company. |
| 40 |
- The value must be between 1 and 64 characters in length. |
| 41 |
type: str |
| 42 |
extends_documentation_fragment: |
| 43 |
- purestorage.flasharray.purestorage.fa |
| 44 |
""" |
| 45 |
|
| 46 |
EXAMPLES = r""" |
| 47 |
- name: Sign EULA for FlashArray |
| 48 |
purestorage.flasharray.purefa_eula: |
| 49 |
company: "ACME Storage, Inc." |
| 50 |
name: "Fred Bloggs" |
| 51 |
title: "Storage Manager" |
| 52 |
fa_url: 10.10.10.2 |
| 53 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 54 |
""" |
| 55 |
|
| 56 |
RETURN = r""" |
| 57 |
""" |
| 58 |
|
| 59 |
from ansible.module_utils.basic import AnsibleModule |
| 60 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 61 |
get_array, |
| 62 |
purefa_argument_spec, |
| 63 |
) |
| 64 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 65 |
LooseVersion, |
| 66 |
) |
| 67 |
|
| 68 |
HAS_PURESTORAGE = True |
| 69 |
try: |
| 70 |
from pypureclient.flasharray import Eula, EulaSignature |
| 71 |
except ImportError: |
| 72 |
HAS_PURESTORAGE = False |
| 73 |
|
| 74 |
|
| 75 |
EULA_V2 = "2.30" |
| 76 |
|
| 77 |
|
| 78 |
def set_eula(module, array): |
| 79 |
"""Sign EULA""" |
| 80 |
changed = False |
| 81 |
res = array.get_arrays_eula() |
| 82 |
if res.status_code == 200: |
| 83 |
current_eula = list(res.items)[0] |
| 84 |
else: |
| 85 |
module.fail_json( |
| 86 |
msg="Failed to get current EULA. Error: {0}".format(res.errors[0].message) |
| 87 |
) |
| 88 |
if not hasattr(current_eula, "signature.accepted"): |
| 89 |
changed = True |
| 90 |
if not module.check_mode: |
| 91 |
res = array.patch_arrays_eula( |
| 92 |
eula=Eula( |
| 93 |
signature=EulaSignature( |
| 94 |
company=module.params["company"], |
| 95 |
title=module.params["title"], |
| 96 |
name=module.params["name"], |
| 97 |
) |
| 98 |
) |
| 99 |
) |
| 100 |
if res.status_code != 200: |
| 101 |
module.fail_json( |
| 102 |
msg="Signing EULA failed. Error: {0}".format(res.erroros[0].message) |
| 103 |
) |
| 104 |
else: |
| 105 |
module.warn("EULA already signed") |
| 106 |
module.exit_json(changed=changed) |
| 107 |
|
| 108 |
|
| 109 |
def main(): |
| 110 |
argument_spec = purefa_argument_spec() |
| 111 |
argument_spec.update( |
| 112 |
dict( |
| 113 |
company=dict(type="str"), |
| 114 |
name=dict(type="str"), |
| 115 |
title=dict(type="str"), |
| 116 |
) |
| 117 |
) |
| 118 |
|
| 119 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 120 |
if not HAS_PURESTORAGE: |
| 121 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 122 |
|
| 123 |
array = get_array(module) |
| 124 |
api_version = array.get_rest_version() |
| 125 |
if LooseVersion(EULA_V2) > LooseVersion(api_version): |
| 126 |
if not ( |
| 127 |
module.params["company"] |
| 128 |
and module.params["title"] |
| 129 |
and module.params["name"] |
| 130 |
): |
| 131 |
module.fail_json(msg="missing required arguments: company, name, title") |
| 132 |
set_eula(module, array) |
| 133 |
|
| 134 |
module.exit_json(changed=False) |
| 135 |
|
| 136 |
|
| 137 |
if __name__ == "__main__": |
| 138 |
main() |