1#!/usr/bin/python 2# -*- coding: utf-8 -*- 3 4# (c) 2018, Simon Dodsley (simon@purestorage.com) 5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 7from __future__ import absolute_import, division, print_function 8__metaclass__ = type 9 10ANSIBLE_METADATA = {'metadata_version': '1.1', 11 'status': ['preview'], 12 'supported_by': 'community'} 13 14DOCUMENTATION = r''' 15--- 16module: purefa_phonehome 17version_added: '2.9' 18short_description: Enable or Disable Pure Storage FlashArray Phonehome 19description: 20- Enable or Disable Phonehome for a Pure Storage FlashArray. 21author: 22- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com> 23options: 24 state: 25 description: 26 - Define state of phonehome 27 type: str 28 default: present 29 choices: [ present, absent ] 30extends_documentation_fragment: 31- purestorage.fa 32''' 33 34EXAMPLES = r''' 35- name: Enable Phonehome 36 purefa_phonehome: 37 fa_url: 10.10.10.2 38 api_token: e31060a7-21fc-e277-6240-25983c6c4592 39 40- name: Disable Phonehome 41 purefa_phonehome: 42 state: disable 43 fa_url: 10.10.10.2 44 api_token: e31060a7-21fc-e277-6240-25983c6c4592 45''' 46 47RETURN = r''' 48''' 49 50from ansible.module_utils.basic import AnsibleModule 51from ansible.module_utils.pure import get_system, purefa_argument_spec 52 53 54def enable_ph(module, array): 55 """Enable Remote Assist""" 56 changed = False 57 if array.get_phonehome()['phonehome'] != 'enabled': 58 try: 59 if not module.check_mode: 60 array.enable_phonehome() 61 changed = True 62 except Exception: 63 module.fail_json(msg='Enabling Phonehome failed') 64 module.exit_json(changed=changed) 65 66 67def disable_ph(module, array): 68 """Disable Remote Assist""" 69 changed = False 70 if array.get_phonehome()['phonehome'] == 'enabled': 71 try: 72 if not module.check_mode: 73 array.disable_phonehome() 74 changed = True 75 except Exception: 76 module.fail_json(msg='Disabling Remote Assist failed') 77 module.exit_json(changed=changed) 78 79 80def main(): 81 argument_spec = purefa_argument_spec() 82 argument_spec.update(dict( 83 state=dict(type='str', default='present', choices=['present', 'absent']), 84 )) 85 86 module = AnsibleModule(argument_spec, 87 supports_check_mode=True) 88 89 array = get_system(module) 90 91 if module.params['state'] == 'present': 92 enable_ph(module, array) 93 else: 94 disable_ph(module, array) 95 module.exit_json(changed=False) 96 97 98if __name__ == '__main__': 99 main() 100