| 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_phonehome |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Enable or Disable Pure Storage FlashArray Phonehome |
| 22 |
description: |
| 23 |
- Enablke or Disable Phonehome 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 phonehome |
| 30 |
type: str |
| 31 |
default: present |
| 32 |
choices: [ present, absent ] |
| 33 |
excludes: |
| 34 |
description: |
| 35 |
- Items that are excluded from phonehome data collection |
| 36 |
type: list |
| 37 |
elements: str |
| 38 |
choices: [ "application-insights" ] |
| 39 |
version_added: '1.40.0' |
| 40 |
extends_documentation_fragment: |
| 41 |
- purestorage.flasharray.purestorage.fa |
| 42 |
""" |
| 43 |
|
| 44 |
EXAMPLES = r""" |
| 45 |
- name: Enable Phonehome |
| 46 |
purestorage.flasharray.purefa_phonehome: |
| 47 |
fa_url: 10.10.10.2 |
| 48 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 49 |
|
| 50 |
- name: Disable Phonehome |
| 51 |
purestorage.flasharray.purefa_phonehome: |
| 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 SupportPatch |
| 63 |
except ImportError: |
| 64 |
HAS_PURESTORAGE = False |
| 65 |
|
| 66 |
from ansible.module_utils.basic import AnsibleModule |
| 67 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 68 |
get_array, |
| 69 |
purefa_argument_spec, |
| 70 |
) |
| 71 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 72 |
LooseVersion, |
| 73 |
) |
| 74 |
|
| 75 |
EXCLUDES_API_VERSION = "2.47" |
| 76 |
|
| 77 |
|
| 78 |
def main(): |
| 79 |
argument_spec = purefa_argument_spec() |
| 80 |
argument_spec.update( |
| 81 |
dict( |
| 82 |
state=dict(type="str", default="present", choices=["present", "absent"]), |
| 83 |
excludes=dict( |
| 84 |
type="list", elements="str", choices=["application-insights"] |
| 85 |
), |
| 86 |
) |
| 87 |
) |
| 88 |
|
| 89 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 90 |
|
| 91 |
if not HAS_PURESTORAGE: |
| 92 |
module.fail_json(msg="py-pure-client sdk is required to for this module") |
| 93 |
|
| 94 |
array = get_array(module) |
| 95 |
api_version = array.get_rest_version() |
| 96 |
support = list(array.get_support().items)[0] |
| 97 |
phonehome = support.phonehome_enabled |
| 98 |
excludes = getattr(support, "phonehome_excludes", None) |
| 99 |
changed = False |
| 100 |
if module.params["state"] == "present" and not phonehome: |
| 101 |
changed = True |
| 102 |
if not module.check_mode: |
| 103 |
res = array.patch_support(support=SupportPatch(phonehome_enabled=True)) |
| 104 |
if res.status_code != 200: |
| 105 |
module.fail_json( |
| 106 |
msg="Enabling Phonehome failed. Error: {0}".format( |
| 107 |
res.errors[0].message |
| 108 |
) |
| 109 |
) |
| 110 |
if ( |
| 111 |
LooseVersion(EXCLUDES_API_VERSION) <= LooseVersion(api_version) |
| 112 |
and module.params["excludes"] |
| 113 |
): |
| 114 |
res = array.patch_support( |
| 115 |
support=SupportPatch(phonehome_excludes=module.params["excludes"]) |
| 116 |
) |
| 117 |
if res.status_code != 200: |
| 118 |
module.fail_json( |
| 119 |
msg="Updating Phonehome failed. Error: {0}".format( |
| 120 |
res.errors[0].message |
| 121 |
) |
| 122 |
) |
| 123 |
elif module.params["state"] == "present" and phonehome: |
| 124 |
if LooseVersion(EXCLUDES_API_VERSION) <= LooseVersion(api_version): |
| 125 |
if module.params["excludes"] != excludes: |
| 126 |
changed = True |
| 127 |
if not module.check_mode: |
| 128 |
res = array.patch_support( |
| 129 |
support=SupportPatch( |
| 130 |
phonehome_excludes=module.params["excludes"] |
| 131 |
) |
| 132 |
) |
| 133 |
if res.status_code != 200: |
| 134 |
module.fail_json( |
| 135 |
msg="Updating Phonehome failed. Error: {0}".format( |
| 136 |
res.errors[0].message |
| 137 |
) |
| 138 |
) |
| 139 |
elif module.params["state"] == "absent" and phonehome: |
| 140 |
changed = True |
| 141 |
if not module.check_mode: |
| 142 |
res = array.patch_support(support=SupportPatch(phonehome_enabled=False)) |
| 143 |
if res.status_code != 200: |
| 144 |
module.fail_json( |
| 145 |
msg="Disabling Phonehome failed. Error: {0}".format( |
| 146 |
res.errors[0].message |
| 147 |
) |
| 148 |
) |
| 149 |
module.exit_json(changed=changed) |
| 150 |
|
| 151 |
|
| 152 |
if __name__ == "__main__": |
| 153 |
main() |