| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# (c) 2021-2025, NetApp, Inc |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
from __future__ import absolute_import, division, print_function |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
DOCUMENTATION = """ |
| 10 |
module: na_ontap_fdss |
| 11 |
short_description: NetApp ONTAP File Directory Security Set. |
| 12 |
extends_documentation_fragment: |
| 13 |
- netapp.ontap.netapp.na_ontap_rest |
| 14 |
version_added: 21.8.0 |
| 15 |
author: NetApp Ansible Team (@carchi8py) <[email protected]> |
| 16 |
|
| 17 |
description: |
| 18 |
- Set file directory security information. |
| 19 |
- This module is not idempotent. If re-running this module to apply the currently assigned policy, the policy will be reassigned. |
| 20 |
options: |
| 21 |
state: |
| 22 |
description: |
| 23 |
- Whether the specified Policy Task should exist or not. |
| 24 |
choices: ['present'] |
| 25 |
default: present |
| 26 |
type: str |
| 27 |
name: |
| 28 |
description: |
| 29 |
- Specifies the security policy to apply. |
| 30 |
required: true |
| 31 |
type: str |
| 32 |
|
| 33 |
vserver: |
| 34 |
description: |
| 35 |
- Specifies the Vserver that contains the path to which the security policy is applied. |
| 36 |
required: true |
| 37 |
type: str |
| 38 |
""" |
| 39 |
EXAMPLES = """ |
| 40 |
- name: Set File Directory Security |
| 41 |
netapp.ontap.na_ontap_fdss: |
| 42 |
state: present |
| 43 |
vserver: "svm1" |
| 44 |
name: "ansible_pl" |
| 45 |
hostname: "{{ hostname }}" |
| 46 |
username: "{{ username }}" |
| 47 |
password: "{{ password }}" |
| 48 |
""" |
| 49 |
|
| 50 |
RETURN = """ |
| 51 |
|
| 52 |
""" |
| 53 |
|
| 54 |
from ansible.module_utils.basic import AnsibleModule |
| 55 |
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils |
| 56 |
from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule |
| 57 |
from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI |
| 58 |
import ansible_collections.netapp.ontap.plugins.module_utils.rest_response_helpers as rrh |
| 59 |
|
| 60 |
|
| 61 |
class NetAppOntapFDSS(): |
| 62 |
""" |
| 63 |
Applys a File Directory Security Policy |
| 64 |
""" |
| 65 |
def __init__(self): |
| 66 |
""" |
| 67 |
Initialize the Ontap File Directory Security class |
| 68 |
""" |
| 69 |
|
| 70 |
self.argument_spec = netapp_utils.na_ontap_rest_only_spec() |
| 71 |
self.argument_spec.update(dict( |
| 72 |
state=dict(required=False, choices=['present'], default='present'), |
| 73 |
name=dict(required=True, type='str'), |
| 74 |
vserver=dict(required=True, type='str'), |
| 75 |
)) |
| 76 |
|
| 77 |
self.module = AnsibleModule( |
| 78 |
argument_spec=self.argument_spec, |
| 79 |
supports_check_mode=True |
| 80 |
) |
| 81 |
|
| 82 |
# set up variables |
| 83 |
self.na_helper = NetAppModule() |
| 84 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 85 |
|
| 86 |
self.rest_api = OntapRestAPI(self.module) |
| 87 |
self.use_rest = self.rest_api.is_rest() |
| 88 |
|
| 89 |
if not self.use_rest: |
| 90 |
self.module.fail_json(msg=self.rest_api.requires_ontap_version('na_ontap_fdss', '9.6')) |
| 91 |
|
| 92 |
def set_fdss(self): |
| 93 |
""" |
| 94 |
Apply File Directory Security |
| 95 |
""" |
| 96 |
|
| 97 |
api = "private/cli/vserver/security/file-directory/apply" |
| 98 |
query = { |
| 99 |
'policy_name': self.parameters['name'], |
| 100 |
'vserver': self.parameters['vserver'], |
| 101 |
} |
| 102 |
|
| 103 |
response, error = self.rest_api.post(api, query) # response will contain the job ID created by the post. |
| 104 |
response, error = rrh.check_for_error_and_job_results(api, response, error, self.rest_api) |
| 105 |
|
| 106 |
if error: |
| 107 |
self.module.fail_json(msg=error) |
| 108 |
|
| 109 |
def apply(self): |
| 110 |
self.set_fdss() |
| 111 |
self.module.exit_json(changed=True) |
| 112 |
|
| 113 |
|
| 114 |
def main(): |
| 115 |
""" |
| 116 |
File Directory Security Policy Tasks |
| 117 |
""" |
| 118 |
obj = NetAppOntapFDSS() |
| 119 |
obj.apply() |
| 120 |
|
| 121 |
|
| 122 |
if __name__ == '__main__': |
| 123 |
main() |