HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible_collections/netapp/ontap/plugins/modules/na_ontap_fdss.py
# (c) 2021, NetApp, Inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

DOCUMENTATION = """
module: na_ontap_fdss
short_description: NetApp ONTAP File Directory Security Set.
extends_documentation_fragment:
    - netapp.ontap.netapp.na_ontap
version_added: 21.8.0
author: NetApp Ansible Team (@carchi8py) <[email protected]>

description:
- Set file directory security information.
- This module is not idempotent. If re-running this module to apply the currently assigned policy, the policy will be reassigned.
options:
  state:
    description:
    - Whether the specified Policy Task should exist or not.
    choices: ['present']
    default: present
    type: str
  name:
    description:
    - Specifies the security policy to apply.
    required: true
    type: str

  vserver:
    description:
    - Specifies the Vserver that contains the path to which the security policy is applied.
    required: true
    type: str
"""
EXAMPLES = """
    - name: Set File Directory Security
      netapp.ontap.na_ontap_fdss:
        state: present
        vserver: "svm1"
        name: "ansible_pl"
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
"""

RETURN = """

"""

from ansible.module_utils.basic import AnsibleModule
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI
import ansible_collections.netapp.ontap.plugins.module_utils.rest_response_helpers as rrh


class NetAppOntapFDSS():
    """
        Applys a File Directory Security Policy
    """
    def __init__(self):
        """
            Initialize the Ontap File Directory Security class
        """

        self.argument_spec = netapp_utils.na_ontap_host_argument_spec()
        self.argument_spec.update(dict(
            state=dict(required=False, choices=['present'], default='present'),
            name=dict(required=True, type='str'),
            vserver=dict(required=True, type='str'),
        ))

        self.module = AnsibleModule(
            argument_spec=self.argument_spec,
            supports_check_mode=True
        )

        # set up variables
        self.na_helper = NetAppModule()
        self.parameters = self.na_helper.set_parameters(self.module.params)

        self.rest_api = OntapRestAPI(self.module)
        self.use_rest = self.rest_api.is_rest()

        if not self.use_rest:
            self.module.fail_json(msg=self.rest_api.requires_ontap_version('na_ontap_fdss', '9.6'))

    def set_fdss(self):
        """
        Apply File Directory Security
        """

        api = "private/cli/vserver/security/file-directory/apply"
        query = {
            'policy_name': self.parameters['name'],
            'vserver': self.parameters['vserver'],
        }

        response, error = self.rest_api.post(api, query)  # response will contain the job ID created by the post.
        response, error = rrh.check_for_error_and_job_results(api, response, error, self.rest_api)

        if error:
            self.module.fail_json(msg=error)

    def apply(self):
        self.set_fdss()
        self.module.exit_json(changed=True)


def main():
    """
    File Directory Security Policy Tasks
    """
    obj = NetAppOntapFDSS()
    obj.apply()


if __name__ == '__main__':
    main()