| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 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_ldap_dynamicmapping |
| 15 |
short_description: Configure LDAP server entries. |
| 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 |
ldap: |
| 29 |
description: The parameter (ldap) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
user_ldap_dynamicmapping: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
_scope: |
| 38 |
type: list |
| 39 |
elements: dict |
| 40 |
description: Scope. |
| 41 |
suboptions: |
| 42 |
name: |
| 43 |
type: str |
| 44 |
description: Name. |
| 45 |
vdom: |
| 46 |
type: str |
| 47 |
description: Vdom. |
| 48 |
account_key_filter: |
| 49 |
aliases: ['account-key-filter'] |
| 50 |
type: str |
| 51 |
description: Account key filter. |
| 52 |
account_key_name: |
| 53 |
aliases: ['account-key-name'] |
| 54 |
type: str |
| 55 |
description: Account key name. |
| 56 |
account_key_processing: |
| 57 |
aliases: ['account-key-processing'] |
| 58 |
type: str |
| 59 |
description: Account key processing. |
| 60 |
choices: ['same', 'strip'] |
| 61 |
ca_cert: |
| 62 |
aliases: ['ca-cert'] |
| 63 |
type: str |
| 64 |
description: Ca cert. |
| 65 |
cnid: |
| 66 |
type: str |
| 67 |
description: Cnid. |
| 68 |
dn: |
| 69 |
type: str |
| 70 |
description: Dn. |
| 71 |
filter: |
| 72 |
type: str |
| 73 |
description: Filter. |
| 74 |
group: |
| 75 |
type: str |
| 76 |
description: Group. |
| 77 |
group_filter: |
| 78 |
aliases: ['group-filter'] |
| 79 |
type: str |
| 80 |
description: Group filter. |
| 81 |
group_member_check: |
| 82 |
aliases: ['group-member-check'] |
| 83 |
type: str |
| 84 |
description: Group member check. |
| 85 |
choices: ['user-attr', 'group-object', 'posix-group-object'] |
| 86 |
group_object_filter: |
| 87 |
aliases: ['group-object-filter'] |
| 88 |
type: str |
| 89 |
description: Group object filter. |
| 90 |
group_object_search_base: |
| 91 |
aliases: ['group-object-search-base'] |
| 92 |
type: str |
| 93 |
description: Group object search base. |
| 94 |
group_search_base: |
| 95 |
aliases: ['group-search-base'] |
| 96 |
type: str |
| 97 |
description: Group search base. |
| 98 |
member_attr: |
| 99 |
aliases: ['member-attr'] |
| 100 |
type: str |
| 101 |
description: Member attr. |
| 102 |
obtain_user_info: |
| 103 |
aliases: ['obtain-user-info'] |
| 104 |
type: str |
| 105 |
description: Obtain user info. |
| 106 |
choices: ['disable', 'enable'] |
| 107 |
password: |
| 108 |
type: raw |
| 109 |
description: (list) Password. |
| 110 |
password_expiry_warning: |
| 111 |
aliases: ['password-expiry-warning'] |
| 112 |
type: str |
| 113 |
description: Password expiry warning. |
| 114 |
choices: ['disable', 'enable'] |
| 115 |
password_renewal: |
| 116 |
aliases: ['password-renewal'] |
| 117 |
type: str |
| 118 |
description: Password renewal. |
| 119 |
choices: ['disable', 'enable'] |
| 120 |
port: |
| 121 |
type: int |
| 122 |
description: Port. |
| 123 |
retrieve_protection_profile: |
| 124 |
aliases: ['retrieve-protection-profile'] |
| 125 |
type: str |
| 126 |
description: Retrieve protection profile. |
| 127 |
search_type: |
| 128 |
aliases: ['search-type'] |
| 129 |
type: list |
| 130 |
elements: str |
| 131 |
description: Search type. |
| 132 |
choices: ['nested', 'recursive'] |
| 133 |
secondary_server: |
| 134 |
aliases: ['secondary-server'] |
| 135 |
type: str |
| 136 |
description: Secondary server. |
| 137 |
secure: |
| 138 |
type: str |
| 139 |
description: Secure. |
| 140 |
choices: ['disable', 'starttls', 'ldaps'] |
| 141 |
server: |
| 142 |
type: str |
| 143 |
description: Server. |
| 144 |
server_identity_check: |
| 145 |
aliases: ['server-identity-check'] |
| 146 |
type: str |
| 147 |
description: Server identity check. |
| 148 |
choices: ['disable', 'enable'] |
| 149 |
source_ip: |
| 150 |
aliases: ['source-ip'] |
| 151 |
type: str |
| 152 |
description: Source ip. |
| 153 |
ssl_min_proto_version: |
| 154 |
aliases: ['ssl-min-proto-version'] |
| 155 |
type: str |
| 156 |
description: Ssl min proto version. |
| 157 |
choices: ['default', 'TLSv1', 'TLSv1-1', 'TLSv1-2', 'SSLv3', 'TLSv1-3'] |
| 158 |
tertiary_server: |
| 159 |
aliases: ['tertiary-server'] |
| 160 |
type: str |
| 161 |
description: Tertiary server. |
| 162 |
type: |
| 163 |
type: str |
| 164 |
description: Type. |
| 165 |
choices: ['simple', 'anonymous', 'regular'] |
| 166 |
user_info_exchange_server: |
| 167 |
aliases: ['user-info-exchange-server'] |
| 168 |
type: str |
| 169 |
description: User info exchange server. |
| 170 |
username: |
| 171 |
type: str |
| 172 |
description: Username. |
| 173 |
two_factor: |
| 174 |
aliases: ['two-factor'] |
| 175 |
type: str |
| 176 |
description: Two factor. |
| 177 |
choices: ['disable', 'fortitoken-cloud'] |
| 178 |
interface: |
| 179 |
type: str |
| 180 |
description: Interface. |
| 181 |
interface_select_method: |
| 182 |
aliases: ['interface-select-method'] |
| 183 |
type: str |
| 184 |
description: Interface select method. |
| 185 |
choices: ['auto', 'sdwan', 'specify'] |
| 186 |
two_factor_authentication: |
| 187 |
aliases: ['two-factor-authentication'] |
| 188 |
type: str |
| 189 |
description: Two factor authentication. |
| 190 |
choices: ['fortitoken', 'email', 'sms'] |
| 191 |
two_factor_notification: |
| 192 |
aliases: ['two-factor-notification'] |
| 193 |
type: str |
| 194 |
description: Two factor notification. |
| 195 |
choices: ['email', 'sms'] |
| 196 |
antiphish: |
| 197 |
type: str |
| 198 |
description: Enable/disable AntiPhishing credential backend. |
| 199 |
choices: ['disable', 'enable'] |
| 200 |
password_attr: |
| 201 |
aliases: ['password-attr'] |
| 202 |
type: str |
| 203 |
description: Name of attribute to get password hash. |
| 204 |
source_port: |
| 205 |
aliases: ['source-port'] |
| 206 |
type: int |
| 207 |
description: Source port to be used for communication with the LDAP server. |
| 208 |
client_cert: |
| 209 |
aliases: ['client-cert'] |
| 210 |
type: str |
| 211 |
description: Client certificate name. |
| 212 |
client_cert_auth: |
| 213 |
aliases: ['client-cert-auth'] |
| 214 |
type: str |
| 215 |
description: Enable/disable using client certificate for TLS authentication. |
| 216 |
choices: ['disable', 'enable'] |
| 217 |
max_connections: |
| 218 |
aliases: ['max-connections'] |
| 219 |
type: int |
| 220 |
description: Max connections. |
| 221 |
two_factor_filter: |
| 222 |
aliases: ['two-factor-filter'] |
| 223 |
type: str |
| 224 |
description: Filter used to synchronize users to FortiToken Cloud. |
| 225 |
account_key_upn_san: |
| 226 |
aliases: ['account-key-upn-san'] |
| 227 |
type: str |
| 228 |
description: Define SAN in certificate for user principle name matching. |
| 229 |
choices: ['othername', 'rfc822name', 'dnsname'] |
| 230 |
account_key_cert_field: |
| 231 |
aliases: ['account-key-cert-field'] |
| 232 |
type: str |
| 233 |
description: Define subject identity field in certificate for user access right checking. |
| 234 |
choices: ['othername', 'rfc822name', 'dnsname', 'cn'] |
| 235 |
status_ttl: |
| 236 |
aliases: ['status-ttl'] |
| 237 |
type: int |
| 238 |
description: Time for which server reachability is cached so that when a server is unreachable, it will not be retried for at least thi... |
| 239 |
source_ip_interface: |
| 240 |
aliases: ['source-ip-interface'] |
| 241 |
type: raw |
| 242 |
description: (list) Source interface for communication with the LDAP server. |
| 243 |
ssl_max_proto_version: |
| 244 |
aliases: ['ssl-max-proto-version'] |
| 245 |
type: str |
| 246 |
description: Ssl max proto version. |
| 247 |
choices: ['TLSv1-1', 'TLSv1-2', 'SSLv3', 'TLSv1', 'TLSv1-3'] |
| 248 |
vrf_select: |
| 249 |
aliases: ['vrf-select'] |
| 250 |
type: int |
| 251 |
description: VRF ID used for connection to server. |
| 252 |
validate_server_certificate: |
| 253 |
aliases: ['validate-server-certificate'] |
| 254 |
type: str |
| 255 |
description: Validate server certificate. |
| 256 |
choices: ['disable', 'enable'] |
| 257 |
''' |
| 258 |
|
| 259 |
EXAMPLES = ''' |
| 260 |
- name: Example playbook |
| 261 |
hosts: fortimanagers |
| 262 |
gather_facts: false |
| 263 |
connection: httpapi |
| 264 |
vars: |
| 265 |
ansible_httpapi_use_ssl: true |
| 266 |
ansible_httpapi_validate_certs: false |
| 267 |
ansible_httpapi_port: 443 |
| 268 |
tasks: |
| 269 |
- name: Configure dynamic mappings of LDAP server |
| 270 |
fortinet.fortimanager.fmgr_user_ldap_dynamicmapping: |
| 271 |
bypass_validation: false |
| 272 |
adom: ansible |
| 273 |
ldap: ansible-test-ldap # name |
| 274 |
state: present |
| 275 |
user_ldap_dynamicmapping: |
| 276 |
_scope: |
| 277 |
- name: FGT_AWS # need a valid device name |
| 278 |
vdom: root # need a valid vdom name under the device |
| 279 |
dn: ansible-test-dn |
| 280 |
password: fortinet |
| 281 |
port: 9000 |
| 282 |
server: ansible |
| 283 |
username: ansible-test-dyn |
| 284 |
|
| 285 |
- name: Gathering fortimanager facts |
| 286 |
hosts: fortimanagers |
| 287 |
gather_facts: false |
| 288 |
connection: httpapi |
| 289 |
vars: |
| 290 |
ansible_httpapi_use_ssl: true |
| 291 |
ansible_httpapi_validate_certs: false |
| 292 |
ansible_httpapi_port: 443 |
| 293 |
tasks: |
| 294 |
- name: Retrieve all the dynamic mappings of LDAP server |
| 295 |
fortinet.fortimanager.fmgr_fact: |
| 296 |
facts: |
| 297 |
selector: "user_ldap_dynamicmapping" |
| 298 |
params: |
| 299 |
adom: "ansible" |
| 300 |
ldap: "ansible-test-ldap" # name |
| 301 |
dynamic_mapping: "your_value" |
| 302 |
''' |
| 303 |
|
| 304 |
RETURN = ''' |
| 305 |
meta: |
| 306 |
description: The result of the request. |
| 307 |
type: dict |
| 308 |
returned: always |
| 309 |
contains: |
| 310 |
request_url: |
| 311 |
description: The full url requested. |
| 312 |
returned: always |
| 313 |
type: str |
| 314 |
sample: /sys/login/user |
| 315 |
response_code: |
| 316 |
description: The status of api request. |
| 317 |
returned: always |
| 318 |
type: int |
| 319 |
sample: 0 |
| 320 |
response_data: |
| 321 |
description: The api response. |
| 322 |
type: list |
| 323 |
returned: always |
| 324 |
response_message: |
| 325 |
description: The descriptive message of the api response. |
| 326 |
type: str |
| 327 |
returned: always |
| 328 |
sample: OK. |
| 329 |
system_information: |
| 330 |
description: The information of the target system. |
| 331 |
type: dict |
| 332 |
returned: always |
| 333 |
rc: |
| 334 |
description: The status the request. |
| 335 |
type: int |
| 336 |
returned: always |
| 337 |
sample: 0 |
| 338 |
version_check_warning: |
| 339 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 340 |
type: list |
| 341 |
returned: complex |
| 342 |
''' |
| 343 |
from ansible.module_utils.basic import AnsibleModule |
| 344 |
from ansible.module_utils.connection import Connection |
| 345 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 346 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 347 |
|
| 348 |
|
| 349 |
def main(): |
| 350 |
urls_list = [ |
| 351 |
'/pm/config/adom/{adom}/obj/user/ldap/{ldap}/dynamic_mapping', |
| 352 |
'/pm/config/global/obj/user/ldap/{ldap}/dynamic_mapping' |
| 353 |
] |
| 354 |
module_arg_spec = { |
| 355 |
'adom': {'required': True, 'type': 'str'}, |
| 356 |
'ldap': {'required': True, 'type': 'str'}, |
| 357 |
'revision_note': {'type': 'str'}, |
| 358 |
'user_ldap_dynamicmapping': { |
| 359 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 360 |
'options': { |
| 361 |
'_scope': {'type': 'list', 'options': {'name': {'type': 'str'}, 'vdom': {'type': 'str'}}, 'elements': 'dict'}, |
| 362 |
'account-key-filter': {'no_log': True, 'type': 'str'}, |
| 363 |
'account-key-name': {'no_log': True, 'type': 'str'}, |
| 364 |
'account-key-processing': {'choices': ['same', 'strip'], 'type': 'str'}, |
| 365 |
'ca-cert': {'type': 'str'}, |
| 366 |
'cnid': {'type': 'str'}, |
| 367 |
'dn': {'type': 'str'}, |
| 368 |
'filter': {'type': 'str'}, |
| 369 |
'group': {'type': 'str'}, |
| 370 |
'group-filter': {'type': 'str'}, |
| 371 |
'group-member-check': {'choices': ['user-attr', 'group-object', 'posix-group-object'], 'type': 'str'}, |
| 372 |
'group-object-filter': {'type': 'str'}, |
| 373 |
'group-object-search-base': {'type': 'str'}, |
| 374 |
'group-search-base': {'type': 'str'}, |
| 375 |
'member-attr': {'type': 'str'}, |
| 376 |
'obtain-user-info': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 377 |
'password': {'no_log': True, 'type': 'raw'}, |
| 378 |
'password-expiry-warning': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 379 |
'password-renewal': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 380 |
'port': {'type': 'int'}, |
| 381 |
'retrieve-protection-profile': {'type': 'str'}, |
| 382 |
'search-type': {'type': 'list', 'choices': ['nested', 'recursive'], 'elements': 'str'}, |
| 383 |
'secondary-server': {'type': 'str'}, |
| 384 |
'secure': {'choices': ['disable', 'starttls', 'ldaps'], 'type': 'str'}, |
| 385 |
'server': {'type': 'str'}, |
| 386 |
'server-identity-check': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 387 |
'source-ip': {'type': 'str'}, |
| 388 |
'ssl-min-proto-version': {'choices': ['default', 'TLSv1', 'TLSv1-1', 'TLSv1-2', 'SSLv3', 'TLSv1-3'], 'type': 'str'}, |
| 389 |
'tertiary-server': {'type': 'str'}, |
| 390 |
'type': {'choices': ['simple', 'anonymous', 'regular'], 'type': 'str'}, |
| 391 |
'user-info-exchange-server': {'type': 'str'}, |
| 392 |
'username': {'type': 'str'}, |
| 393 |
'two-factor': {'v_range': [['6.2.2', '']], 'choices': ['disable', 'fortitoken-cloud'], 'type': 'str'}, |
| 394 |
'interface': {'v_range': [['6.2.5', '6.2.13'], ['6.4.1', '']], 'type': 'str'}, |
| 395 |
'interface-select-method': {'v_range': [['6.2.5', '6.2.13'], ['6.4.1', '']], 'choices': ['auto', 'sdwan', 'specify'], 'type': 'str'}, |
| 396 |
'two-factor-authentication': {'v_range': [['6.2.5', '']], 'choices': ['fortitoken', 'email', 'sms'], 'type': 'str'}, |
| 397 |
'two-factor-notification': {'v_range': [['6.2.5', '']], 'choices': ['email', 'sms'], 'type': 'str'}, |
| 398 |
'antiphish': {'v_range': [['7.0.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 399 |
'password-attr': {'v_range': [['7.0.0', '']], 'no_log': True, 'type': 'str'}, |
| 400 |
'source-port': {'v_range': [['7.0.0', '']], 'type': 'int'}, |
| 401 |
'client-cert': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 402 |
'client-cert-auth': {'v_range': [['7.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 403 |
'max-connections': {'v_range': [['7.0.11', '7.0.16'], ['7.2.5', '7.2.12'], ['7.4.1', '']], 'type': 'int'}, |
| 404 |
'two-factor-filter': {'v_range': [['7.2.1', '']], 'type': 'str'}, |
| 405 |
'account-key-upn-san': {'v_range': [['7.2.2', '']], 'choices': ['othername', 'rfc822name', 'dnsname'], 'type': 'str'}, |
| 406 |
'account-key-cert-field': {'v_range': [['7.4.1', '']], 'choices': ['othername', 'rfc822name', 'dnsname', 'cn'], 'type': 'str'}, |
| 407 |
'status-ttl': {'v_range': [['7.4.3', '']], 'type': 'int'}, |
| 408 |
'source-ip-interface': {'v_range': [['7.6.0', '']], 'type': 'raw'}, |
| 409 |
'ssl-max-proto-version': { |
| 410 |
'v_range': [['7.2.10', '7.2.12'], ['7.4.4', '7.4.10'], ['7.6.2', '']], |
| 411 |
'choices': ['TLSv1-1', 'TLSv1-2', 'SSLv3', 'TLSv1', 'TLSv1-3'], |
| 412 |
'type': 'str' |
| 413 |
}, |
| 414 |
'vrf-select': {'v_range': [['7.6.2', '']], 'type': 'int'}, |
| 415 |
'validate-server-certificate': {'v_range': [['7.6.3', '']], 'choices': ['disable', 'enable'], 'type': 'str'} |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
module_option_spec = get_module_arg_spec('full crud') |
| 421 |
module_arg_spec.update(module_option_spec) |
| 422 |
check_galaxy_version(module_arg_spec) |
| 423 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_ldap_dynamicmapping'), |
| 424 |
supports_check_mode=True) |
| 425 |
if not module._socket_path: |
| 426 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 427 |
connection = Connection(module._socket_path) |
| 428 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 429 |
'complex:{{module}}["_scope"][0]["name"]+"/"+{{module}}["_scope"][0]["vdom"]', 'data', module, connection) |
| 430 |
fmgr.process_crud() |
| 431 |
module.exit_json(meta=module.params) |
| 432 |
|
| 433 |
|
| 434 |
if __name__ == '__main__': |
| 435 |
main() |