| 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_console |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Enable or Disable Pure Storage FlashArray Console Lock |
| 22 |
description: |
| 23 |
- Enablke or Disable root lockout from the array at the physical console for a Pure Storage FlashArray. |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
state: |
| 28 |
description: |
| 29 |
- Define state of console lockout |
| 30 |
- When set to I(enable) the console port is locked from root login. |
| 31 |
type: str |
| 32 |
default: disable |
| 33 |
choices: [ enable, disable ] |
| 34 |
context: |
| 35 |
description: |
| 36 |
- Name of fleet member on which to perform the operation. |
| 37 |
- This requires the array receiving the request is a member of a fleet |
| 38 |
and the context name to be a member of the same fleet. |
| 39 |
type: str |
| 40 |
default: "" |
| 41 |
version_added: '1.39.0' |
| 42 |
extends_documentation_fragment: |
| 43 |
- purestorage.flasharray.purestorage.fa |
| 44 |
""" |
| 45 |
|
| 46 |
EXAMPLES = r""" |
| 47 |
- name: Enable Console Lockout |
| 48 |
purestorage.flasharray.purefa_console: |
| 49 |
state: enable |
| 50 |
fa_url: 10.10.10.2 |
| 51 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 52 |
|
| 53 |
- name: Disable Console Lockout |
| 54 |
purestorage.flasharray.purefa_console: |
| 55 |
fa_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.flasharray import Arrays |
| 65 |
except ImportError: |
| 66 |
HAS_PYPURECLIENT = False |
| 67 |
|
| 68 |
from ansible.module_utils.basic import AnsibleModule |
| 69 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 70 |
get_array, |
| 71 |
purefa_argument_spec, |
| 72 |
) |
| 73 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 74 |
LooseVersion, |
| 75 |
) |
| 76 |
|
| 77 |
CONTEXT_VERSION = "2.38" |
| 78 |
|
| 79 |
|
| 80 |
def update_console(module, array): |
| 81 |
"""Update Console Lockout setting""" |
| 82 |
changed = False |
| 83 |
api_version = array.get_rest_version() |
| 84 |
if LooseVersion(CONTEXT_VERSION) <= LooseVersion(api_version): |
| 85 |
current_state = list( |
| 86 |
array.get_arrays(context_names=[module.params["context"]]).items |
| 87 |
)[0].console_lock_enabled |
| 88 |
else: |
| 89 |
current_state = list(array.get_arrays().items)[0].console_lock_enabled |
| 90 |
new_state = bool(module.params["state"] == "enable") |
| 91 |
if current_state != new_state: |
| 92 |
changed = True |
| 93 |
if not module.check_mode: |
| 94 |
if LooseVersion(CONTEXT_VERSION) <= LooseVersion(api_version): |
| 95 |
res = array.patch_arrays( |
| 96 |
array=Arrays(console_lock_enabled=new_state), |
| 97 |
context_names=[module.params["context"]], |
| 98 |
) |
| 99 |
else: |
| 100 |
res = array.patch_arrays(array=Arrays(console_lock_enabled=new_state)) |
| 101 |
if res.status_code != 200: |
| 102 |
module.fail_json( |
| 103 |
msg="Enabling Console Lock failed. Error: {0}".format( |
| 104 |
res.errors[0].message |
| 105 |
) |
| 106 |
) |
| 107 |
module.exit_json(changed=changed) |
| 108 |
|
| 109 |
|
| 110 |
def main(): |
| 111 |
argument_spec = purefa_argument_spec() |
| 112 |
argument_spec.update( |
| 113 |
dict( |
| 114 |
state=dict(type="str", default="disable", choices=["enable", "disable"]), |
| 115 |
context=dict(type="str", default=""), |
| 116 |
) |
| 117 |
) |
| 118 |
|
| 119 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 120 |
|
| 121 |
if not HAS_PYPURECLIENT: |
| 122 |
module.fail_json(msg="purestorage sdk is required for this module") |
| 123 |
|
| 124 |
array = get_array(module) |
| 125 |
|
| 126 |
update_console(module, array) |
| 127 |
|
| 128 |
|
| 129 |
if __name__ == "__main__": |
| 130 |
main() |