Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_user_fortitoken.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_user_fortitoken
15 short_description: Configure FortiToken.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 user_fortitoken:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 comments:
34 type: str
35 description: Comment.
36 license:
37 type: str
38 description: Mobile token license.
39 os_ver:
40 aliases: ['os-ver']
41 type: str
42 description: Device Mobile Version.
43 reg_id:
44 aliases: ['reg-id']
45 type: str
46 description: Device Reg ID.
47 serial_number:
48 aliases: ['serial-number']
49 type: str
50 description: Serial number.
51 required: true
52 status:
53 type: str
54 description: Status
55 choices: ['lock', 'active']
56 '''
57
58 EXAMPLES = '''
59 - name: Example playbook
60 hosts: fortimanagers
61 gather_facts: false
62 connection: httpapi
63 vars:
64 ansible_httpapi_use_ssl: true
65 ansible_httpapi_validate_certs: false
66 ansible_httpapi_port: 443
67 tasks:
68 - name: Configure FortiToken.
69 fortinet.fortimanager.fmgr_user_fortitoken:
70 bypass_validation: false
71 adom: ansible
72 state: present
73 user_fortitoken:
74 comments: ansible-comment
75 serial_number: "your_serial_number" # need a valid FortiToken serial number
76 status: lock # <value in [lock, active]>
77
78 - name: Gathering fortimanager facts
79 hosts: fortimanagers
80 gather_facts: false
81 connection: httpapi
82 vars:
83 ansible_httpapi_use_ssl: true
84 ansible_httpapi_validate_certs: false
85 ansible_httpapi_port: 443
86 tasks:
87 - name: Retrieve all the FortiTokens
88 fortinet.fortimanager.fmgr_fact:
89 facts:
90 selector: "user_fortitoken"
91 params:
92 adom: "ansible"
93 fortitoken: "your_value"
94 '''
95
96 RETURN = '''
97 meta:
98 description: The result of the request.
99 type: dict
100 returned: always
101 contains:
102 request_url:
103 description: The full url requested.
104 returned: always
105 type: str
106 sample: /sys/login/user
107 response_code:
108 description: The status of api request.
109 returned: always
110 type: int
111 sample: 0
112 response_data:
113 description: The api response.
114 type: list
115 returned: always
116 response_message:
117 description: The descriptive message of the api response.
118 type: str
119 returned: always
120 sample: OK.
121 system_information:
122 description: The information of the target system.
123 type: dict
124 returned: always
125 rc:
126 description: The status the request.
127 type: int
128 returned: always
129 sample: 0
130 version_check_warning:
131 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
132 type: list
133 returned: complex
134 '''
135 from ansible.module_utils.basic import AnsibleModule
136 from ansible.module_utils.connection import Connection
137 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
138 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
139
140
141 def main():
142 urls_list = [
143 '/pm/config/adom/{adom}/obj/user/fortitoken',
144 '/pm/config/global/obj/user/fortitoken'
145 ]
146 module_arg_spec = {
147 'adom': {'required': True, 'type': 'str'},
148 'revision_note': {'type': 'str'},
149 'user_fortitoken': {
150 'type': 'dict', 'v_range': [['6.0.0', '']], 'no_log': False,
151 'options': {
152 'comments': {'type': 'str'},
153 'license': {'type': 'str'},
154 'os-ver': {'v_range': [['6.0.0', '6.2.5'], ['6.4.0', '6.4.1'], ['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'str'},
155 'reg-id': {'v_range': [['6.0.0', '6.2.5'], ['6.4.0', '6.4.1'], ['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'str'},
156 'serial-number': {'required': True, 'type': 'str'},
157 'status': {'choices': ['lock', 'active'], 'type': 'str'}
158 }
159 }
160 }
161
162 module_option_spec = get_module_arg_spec('full crud')
163 module_arg_spec.update(module_option_spec)
164 check_galaxy_version(module_arg_spec)
165 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_fortitoken'),
166 supports_check_mode=True)
167 if not module._socket_path:
168 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
169 connection = Connection(module._socket_path)
170 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
171 'serial-number', 'data', module, connection)
172 fmgr.process_crud()
173 module.exit_json(meta=module.params)
174
175
176 if __name__ == '__main__':
177 main()