| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: NetApp, Inc |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
DOCUMENTATION = """ |
| 11 |
module: na_ontap_mav_config |
| 12 |
short_description: NetApp ONTAP multi-admin verification (MAV) global setting |
| 13 |
extends_documentation_fragment: |
| 14 |
- netapp.ontap.netapp.na_ontap_rest |
| 15 |
version_added: 23.0.0 |
| 16 |
author: NetApp Ansible Team (@carchi8py) <[email protected]> |
| 17 |
description: |
| 18 |
- Enable/disable multi-admin verification (MAV) configuration. |
| 19 |
- Multi-admin verification is not required to enable the feature. However, it is required to disable the feature. |
| 20 |
- Multi-admin verification is required for any modification to be done while multi-admin approval is enabled. |
| 21 |
- Until the pending request gets approved, request info is returned in the module output. |
| 22 |
Once approved the module needs to be run again to apply the intended updates. |
| 23 |
options: |
| 24 |
state: |
| 25 |
description: |
| 26 |
- Modify MAV global setting, only present is supported. |
| 27 |
choices: ['present'] |
| 28 |
type: str |
| 29 |
default: present |
| 30 |
|
| 31 |
enabled: |
| 32 |
description: |
| 33 |
- Specifies whether multi-admin approval is currently configured or not. |
| 34 |
- By default, the feature is disabled and the value is set to false. |
| 35 |
type: bool |
| 36 |
default: false |
| 37 |
|
| 38 |
required_approvers: |
| 39 |
description: |
| 40 |
- Specifies the required number of approvers to approve the request which is inherited by the rule if required-approvers is not provided for the rule. |
| 41 |
- The default and minimum number of required approvers is 1. |
| 42 |
type: int |
| 43 |
|
| 44 |
approval_groups: |
| 45 |
description: |
| 46 |
- Specifies the list of global approval groups which are inherited by the rule if the approval-groups is not provided for the rule. |
| 47 |
- The default value is an empty list. |
| 48 |
type: list |
| 49 |
elements: str |
| 50 |
|
| 51 |
approval_expiry: |
| 52 |
description: |
| 53 |
- Specifies the time, in ISO-8601 duration format, that the approvers have after a new execution request |
| 54 |
is submitted to approve or disapprove the request before the request expires. |
| 55 |
- The default value is one hour (PT1H), the minimum supported value is one second (PT1S), |
| 56 |
and the maximum supported value is 14 days (P14D). |
| 57 |
type: str |
| 58 |
|
| 59 |
execution_expiry: |
| 60 |
description: |
| 61 |
- Specifies the time, in ISO-8601 duration format, that the authorized users have after a request |
| 62 |
is approved to execute the requested operation before the request expires. |
| 63 |
- The default value is one hour (PT1H), the minimum supported value is one second (PT1S), |
| 64 |
and the maximum supported value is 14 days (P14D). |
| 65 |
type: str |
| 66 |
|
| 67 |
notes: |
| 68 |
- Only supported with REST and requires ONTAP 9.11.1 or later. |
| 69 |
""" |
| 70 |
|
| 71 |
EXAMPLES = """ |
| 72 |
- name: Enable multi-admin approval |
| 73 |
netapp.ontap.na_ontap_mav_config: |
| 74 |
state: present |
| 75 |
enabled: true |
| 76 |
hostname: "{{ netapp_hostname }}" |
| 77 |
username: "{{ netapp_username }}" |
| 78 |
password: "{{ netapp_password }}" |
| 79 |
https: true |
| 80 |
validate_certs: "{{ validate_certs }}" |
| 81 |
use_rest: always |
| 82 |
|
| 83 |
- name: Update MAV configuration |
| 84 |
netapp.ontap.na_ontap_mav_config: |
| 85 |
state: present |
| 86 |
approval_groups: ["group1", "group2"] |
| 87 |
execution_expiry: "P14D" |
| 88 |
approval_expiry: "P14D" |
| 89 |
hostname: "{{ netapp_hostname }}" |
| 90 |
username: "{{ netapp_username }}" |
| 91 |
password: "{{ netapp_password }}" |
| 92 |
https: true |
| 93 |
validate_certs: "{{ validate_certs }}" |
| 94 |
use_rest: always |
| 95 |
|
| 96 |
# this generates multi-admin-verify request which needs approval |
| 97 |
- name: Disable multi-admin approval |
| 98 |
netapp.ontap.na_ontap_mav_config: |
| 99 |
state: present |
| 100 |
enabled: false |
| 101 |
hostname: "{{ netapp_hostname }}" |
| 102 |
username: "{{ netapp_username }}" |
| 103 |
password: "{{ netapp_password }}" |
| 104 |
https: true |
| 105 |
validate_certs: "{{ validate_certs }}" |
| 106 |
use_rest: always |
| 107 |
""" |
| 108 |
|
| 109 |
RETURN = """ |
| 110 |
request_info: |
| 111 |
description: Returns multi-admin-verify request information while trying to disable MAV global setting, empty for enable or modify operations. |
| 112 |
returned: always |
| 113 |
type: dict |
| 114 |
sample: { |
| 115 |
"request_info": { |
| 116 |
"calling: security/multi-admin-verify: got {'message': 'The security multi-admin-verify request (index 1) requires approval.', 'code': '262325'}." |
| 117 |
} |
| 118 |
} |
| 119 |
""" |
| 120 |
|
| 121 |
import traceback |
| 122 |
from ansible.module_utils.basic import AnsibleModule |
| 123 |
from ansible.module_utils._text import to_native |
| 124 |
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils |
| 125 |
from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule |
| 126 |
from ansible_collections.netapp.ontap.plugins.module_utils import rest_generic |
| 127 |
|
| 128 |
|
| 129 |
class NetAppOntapMAVConfig: |
| 130 |
def __init__(self): |
| 131 |
self.argument_spec = netapp_utils.na_ontap_rest_only_spec() |
| 132 |
self.argument_spec.update(dict( |
| 133 |
state=dict(required=False, type='str', choices=['present'], default='present'), |
| 134 |
enabled=dict(required=False, type='bool', default=False), |
| 135 |
required_approvers=dict(required=False, type='int'), |
| 136 |
approval_groups=dict(required=False, type='list', elements='str'), |
| 137 |
approval_expiry=dict(required=False, type='str'), |
| 138 |
execution_expiry=dict(required=False, type='str') |
| 139 |
)) |
| 140 |
|
| 141 |
self.extra_responses = {} |
| 142 |
self.module = AnsibleModule( |
| 143 |
argument_spec=self.argument_spec, |
| 144 |
supports_check_mode=True |
| 145 |
) |
| 146 |
|
| 147 |
self.na_helper = NetAppModule(self.module) |
| 148 |
self.parameters = self.na_helper.check_and_set_parameters(self.module) |
| 149 |
|
| 150 |
self.rest_api = netapp_utils.OntapRestAPI(self.module) |
| 151 |
self.rest_api.fail_if_not_rest_minimum_version('na_ontap_mav_config:', 9, 11, 1) |
| 152 |
|
| 153 |
def get_mav_settings(self): |
| 154 |
""" Retrieves multi-admin-verify settings """ |
| 155 |
api = 'security/multi-admin-verify' |
| 156 |
fields = 'enabled,required_approvers,approval_groups,approval_expiry,execution_expiry' |
| 157 |
record, error = rest_generic.get_one_record(self.rest_api, api, fields=fields) |
| 158 |
if error: |
| 159 |
self.module.fail_json(msg="Error fetching multi-admin-verify global settings: %s" % (to_native(error)), |
| 160 |
exception=traceback.format_exc()) |
| 161 |
if record: |
| 162 |
return { |
| 163 |
'enabled': record.get('enabled'), |
| 164 |
'required_approvers': record.get('required_approvers'), |
| 165 |
'approval_groups': record.get('approval_groups'), |
| 166 |
'approval_expiry': record.get('approval_expiry'), |
| 167 |
'execution_expiry': record.get('execution_expiry') |
| 168 |
} |
| 169 |
return None |
| 170 |
|
| 171 |
def modify_mav_settings(self, modify): |
| 172 |
""" Updates multi-admin-verify settings """ |
| 173 |
api = 'security/multi-admin-verify' |
| 174 |
extra_responses = None |
| 175 |
dummy, error = rest_generic.patch_async(self.rest_api, api, uuid_or_name=None, body=modify) |
| 176 |
|
| 177 |
if error: |
| 178 |
if 'The security multi-admin-verify request' in error and 'requires approval' in error: |
| 179 |
self.na_helper.changed = False |
| 180 |
self.extra_responses = dict(request_info=error) |
| 181 |
else: |
| 182 |
self.module.fail_json(msg="Error modifying multi-admin-verify global settings: %s." % (to_native(error)), |
| 183 |
exception=traceback.format_exc()) |
| 184 |
|
| 185 |
def apply(self): |
| 186 |
current = self.get_mav_settings() |
| 187 |
modify = self.na_helper.get_modified_attributes(current, self.parameters) |
| 188 |
|
| 189 |
if self.na_helper.changed and not self.module.check_mode: |
| 190 |
self.modify_mav_settings(modify) |
| 191 |
result = netapp_utils.generate_result(changed=self.na_helper.changed, modify=modify, extra_responses=self.extra_responses) |
| 192 |
self.module.exit_json(**result) |
| 193 |
|
| 194 |
|
| 195 |
def main(): |
| 196 |
mav_config = NetAppOntapMAVConfig() |
| 197 |
mav_config.apply() |
| 198 |
|
| 199 |
|
| 200 |
if __name__ == '__main__': |
| 201 |
main() |