| 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_eula |
| 20 |
version_added: '1.6.0' |
| 21 |
short_description: Sign Pure Storage FlashBlade EULA |
| 22 |
description: |
| 23 |
- Sign the FlashBlade 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 |
required: true |
| 33 |
name: |
| 34 |
description: |
| 35 |
- Full legal name of the individual at the company who has the authority to accept the terms of the agreement. |
| 36 |
- The value must be between 1 and 64 characters in length. |
| 37 |
type: str |
| 38 |
required: true |
| 39 |
title: |
| 40 |
description: |
| 41 |
- Individual's job title at the company. |
| 42 |
- The value must be between 1 and 64 characters in length. |
| 43 |
type: str |
| 44 |
required: true |
| 45 |
extends_documentation_fragment: |
| 46 |
- purestorage.flashblade.purestorage.fb |
| 47 |
""" |
| 48 |
|
| 49 |
EXAMPLES = r""" |
| 50 |
- name: Sign EULA for FlashBlade |
| 51 |
purestorage.flashblade.purefb_eula: |
| 52 |
company: "ACME Storage, Inc." |
| 53 |
name: "Fred Bloggs" |
| 54 |
title: "Storage Manager" |
| 55 |
fb_url: 10.10.10.2 |
| 56 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 57 |
""" |
| 58 |
|
| 59 |
RETURN = r""" |
| 60 |
""" |
| 61 |
|
| 62 |
HAS_PYPURECLIENT = True |
| 63 |
try: |
| 64 |
from pypureclient.flashblade import Eula, EulaSignature |
| 65 |
except ImportError: |
| 66 |
HAS_PYPURECLIENT = False |
| 67 |
|
| 68 |
|
| 69 |
from ansible.module_utils.basic import AnsibleModule |
| 70 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 71 |
get_system, |
| 72 |
purefb_argument_spec, |
| 73 |
) |
| 74 |
|
| 75 |
|
| 76 |
def set_eula(module, blade): |
| 77 |
"""Sign EULA""" |
| 78 |
changed = False |
| 79 |
if not module.check_mode: |
| 80 |
current_eula = list(blade.get_arrays_eula().items)[0].signature |
| 81 |
if not current_eula.accepted: |
| 82 |
if ( |
| 83 |
current_eula.company != module.params["company"] |
| 84 |
or current_eula.title != module.params["title"] |
| 85 |
or current_eula.name != module.params["name"] |
| 86 |
): |
| 87 |
signature = EulaSignature( |
| 88 |
company=module.params["company"], |
| 89 |
title=module.params["title"], |
| 90 |
name=module.params["name"], |
| 91 |
) |
| 92 |
eula_body = Eula(signature=signature) |
| 93 |
if not module.check_mode: |
| 94 |
changed = True |
| 95 |
rc = blade.patch_arrays_eula(eula=eula_body) |
| 96 |
if rc.status_code != 200: |
| 97 |
module.fail_json(msg="Signing EULA failed") |
| 98 |
module.exit_json(changed=changed) |
| 99 |
|
| 100 |
|
| 101 |
def main(): |
| 102 |
argument_spec = purefb_argument_spec() |
| 103 |
argument_spec.update( |
| 104 |
dict( |
| 105 |
company=dict(type="str", required=True), |
| 106 |
name=dict(type="str", required=True), |
| 107 |
title=dict(type="str", required=True), |
| 108 |
) |
| 109 |
) |
| 110 |
|
| 111 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 112 |
|
| 113 |
blade = get_system(module) |
| 114 |
if not HAS_PYPURECLIENT: |
| 115 |
module.fail_json(msg="py-pure-client SDK required to support this module.") |
| 116 |
blade = get_system(module) |
| 117 |
set_eula(module, blade) |
| 118 |
module.exit_json(changed=False) |
| 119 |
|
| 120 |
|
| 121 |
if __name__ == "__main__": |
| 122 |
main() |