Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_user_peer.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_peer
15 short_description: Configure peer users.
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_peer:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 ca:
34 type: str
35 description: Name of the CA certificate as returned by the execute vpn certificate ca list command.
36 cn:
37 type: str
38 description: Peer certificate common name.
39 cn_type:
40 aliases: ['cn-type']
41 type: str
42 description: Peer certificate common name type.
43 choices: ['string', 'email', 'FQDN', 'ipv4', 'ipv6']
44 ldap_mode:
45 aliases: ['ldap-mode']
46 type: str
47 description: Mode for LDAP peer authentication.
48 choices: ['password', 'principal-name']
49 ldap_password:
50 aliases: ['ldap-password']
51 type: raw
52 description: (list) Password for LDAP server bind.
53 ldap_server:
54 aliases: ['ldap-server']
55 type: str
56 description: Name of an LDAP server defined under the user ldap command.
57 ldap_username:
58 aliases: ['ldap-username']
59 type: str
60 description: Username for LDAP server bind.
61 mandatory_ca_verify:
62 aliases: ['mandatory-ca-verify']
63 type: str
64 description: Determine what happens to the peer if the CA certificate is not installed.
65 choices: ['disable', 'enable']
66 name:
67 type: str
68 description: Peer name.
69 required: true
70 ocsp_override_server:
71 aliases: ['ocsp-override-server']
72 type: str
73 description: Online Certificate Status Protocol
74 passwd:
75 type: raw
76 description: (list) Peers password used for two-factor authentication.
77 subject:
78 type: str
79 description: Peer certificate name constraints.
80 two_factor:
81 aliases: ['two-factor']
82 type: str
83 description: Enable/disable two-factor authentication, applying certificate and password-based authentication.
84 choices: ['disable', 'enable']
85 mfa_mode:
86 aliases: ['mfa-mode']
87 type: str
88 description: MFA mode for remote peer authentication/authorization.
89 choices: ['none', 'password', 'subject-identity']
90 mfa_password:
91 aliases: ['mfa-password']
92 type: raw
93 description: (list) Unified password for remote authentication.
94 mfa_server:
95 aliases: ['mfa-server']
96 type: str
97 description: Name of a remote authenticator.
98 mfa_username:
99 aliases: ['mfa-username']
100 type: str
101 description: Unified username for remote authentication.
102 '''
103
104 EXAMPLES = '''
105 - name: Example playbook
106 hosts: fortimanagers
107 gather_facts: false
108 connection: httpapi
109 vars:
110 ansible_httpapi_use_ssl: true
111 ansible_httpapi_validate_certs: false
112 ansible_httpapi_port: 443
113 tasks:
114 - name: Configure peer users.
115 fortinet.fortimanager.fmgr_user_peer:
116 bypass_validation: false
117 adom: ansible
118 state: present
119 user_peer:
120 cn_type: email # <value in [string, email, FQDN, ...]>
121 name: ansible-test-peer
122 passwd: fortinet
123
124 - name: Gathering fortimanager facts
125 hosts: fortimanagers
126 gather_facts: false
127 connection: httpapi
128 vars:
129 ansible_httpapi_use_ssl: true
130 ansible_httpapi_validate_certs: false
131 ansible_httpapi_port: 443
132 tasks:
133 - name: Retrieve all the peer users
134 fortinet.fortimanager.fmgr_fact:
135 facts:
136 selector: "user_peer"
137 params:
138 adom: "ansible"
139 peer: "your_value"
140 '''
141
142 RETURN = '''
143 meta:
144 description: The result of the request.
145 type: dict
146 returned: always
147 contains:
148 request_url:
149 description: The full url requested.
150 returned: always
151 type: str
152 sample: /sys/login/user
153 response_code:
154 description: The status of api request.
155 returned: always
156 type: int
157 sample: 0
158 response_data:
159 description: The api response.
160 type: list
161 returned: always
162 response_message:
163 description: The descriptive message of the api response.
164 type: str
165 returned: always
166 sample: OK.
167 system_information:
168 description: The information of the target system.
169 type: dict
170 returned: always
171 rc:
172 description: The status the request.
173 type: int
174 returned: always
175 sample: 0
176 version_check_warning:
177 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
178 type: list
179 returned: complex
180 '''
181 from ansible.module_utils.basic import AnsibleModule
182 from ansible.module_utils.connection import Connection
183 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
184 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
185
186
187 def main():
188 urls_list = [
189 '/pm/config/adom/{adom}/obj/user/peer',
190 '/pm/config/global/obj/user/peer'
191 ]
192 module_arg_spec = {
193 'adom': {'required': True, 'type': 'str'},
194 'revision_note': {'type': 'str'},
195 'user_peer': {
196 'type': 'dict', 'v_range': [['6.0.0', '']],
197 'options': {
198 'ca': {'type': 'str'},
199 'cn': {'type': 'str'},
200 'cn-type': {'choices': ['string', 'email', 'FQDN', 'ipv4', 'ipv6'], 'type': 'str'},
201 'ldap-mode': {'choices': ['password', 'principal-name'], 'type': 'str'},
202 'ldap-password': {'no_log': True, 'type': 'raw'},
203 'ldap-server': {'type': 'str'},
204 'ldap-username': {'type': 'str'},
205 'mandatory-ca-verify': {'choices': ['disable', 'enable'], 'type': 'str'},
206 'name': {'required': True, 'type': 'str'},
207 'ocsp-override-server': {'type': 'str'},
208 'passwd': {'no_log': True, 'type': 'raw'},
209 'subject': {'type': 'str'},
210 'two-factor': {'choices': ['disable', 'enable'], 'type': 'str'},
211 'mfa-mode': {'v_range': [['7.4.1', '']], 'choices': ['none', 'password', 'subject-identity'], 'type': 'str'},
212 'mfa-password': {'v_range': [['7.4.1', '']], 'no_log': True, 'type': 'raw'},
213 'mfa-server': {'v_range': [['7.4.1', '']], 'type': 'str'},
214 'mfa-username': {'v_range': [['7.4.1', '']], 'type': 'str'}
215 }
216 }
217 }
218
219 module_option_spec = get_module_arg_spec('full crud')
220 module_arg_spec.update(module_option_spec)
221 check_galaxy_version(module_arg_spec)
222 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_peer'),
223 supports_check_mode=True)
224 if not module._socket_path:
225 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
226 connection = Connection(module._socket_path)
227 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
228 'name', 'data', module, connection)
229 fmgr.process_crud()
230 module.exit_json(meta=module.params)
231
232
233 if __name__ == '__main__':
234 main()