| 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_system_admin_ldap |
| 15 |
short_description: LDAP server entry configuration. |
| 16 |
version_added: "2.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.full_crud |
| 20 |
options: |
| 21 |
system_admin_ldap: |
| 22 |
description: The top level parameters set. |
| 23 |
required: false |
| 24 |
type: dict |
| 25 |
suboptions: |
| 26 |
adom: |
| 27 |
type: list |
| 28 |
elements: dict |
| 29 |
description: Adom. |
| 30 |
suboptions: |
| 31 |
adom_name: |
| 32 |
aliases: ['adom-name'] |
| 33 |
type: str |
| 34 |
description: Admin domain names. |
| 35 |
adom_attr: |
| 36 |
aliases: ['adom-attr'] |
| 37 |
type: str |
| 38 |
description: Attribute used to retrieve adom |
| 39 |
attributes: |
| 40 |
type: str |
| 41 |
description: Attributes used for group searching. |
| 42 |
ca_cert: |
| 43 |
aliases: ['ca-cert'] |
| 44 |
type: str |
| 45 |
description: CA certificate name. |
| 46 |
cnid: |
| 47 |
type: str |
| 48 |
description: Common Name Identifier |
| 49 |
connect_timeout: |
| 50 |
aliases: ['connect-timeout'] |
| 51 |
type: int |
| 52 |
description: LDAP connection timeout |
| 53 |
dn: |
| 54 |
type: str |
| 55 |
description: Distinguished Name. |
| 56 |
filter: |
| 57 |
type: str |
| 58 |
description: Filter used for group searching. |
| 59 |
group: |
| 60 |
type: str |
| 61 |
description: Full base DN used for group searching. |
| 62 |
memberof_attr: |
| 63 |
aliases: ['memberof-attr'] |
| 64 |
type: str |
| 65 |
description: Attribute used to retrieve memeberof. |
| 66 |
name: |
| 67 |
type: str |
| 68 |
description: LDAP server entry name. |
| 69 |
required: true |
| 70 |
password: |
| 71 |
type: raw |
| 72 |
description: (list) Password for initial binding. |
| 73 |
port: |
| 74 |
type: int |
| 75 |
description: Port number of LDAP server |
| 76 |
profile_attr: |
| 77 |
aliases: ['profile-attr'] |
| 78 |
type: str |
| 79 |
description: Attribute used to retrieve admin profile. |
| 80 |
secondary_server: |
| 81 |
aliases: ['secondary-server'] |
| 82 |
type: str |
| 83 |
description: No description |
| 84 |
secure: |
| 85 |
type: str |
| 86 |
description: |
| 87 |
- SSL connection. |
| 88 |
- disable - No SSL. |
| 89 |
- starttls - Use StartTLS. |
| 90 |
- ldaps - Use LDAPS. |
| 91 |
choices: ['disable', 'starttls', 'ldaps'] |
| 92 |
server: |
| 93 |
type: str |
| 94 |
description: No description |
| 95 |
tertiary_server: |
| 96 |
aliases: ['tertiary-server'] |
| 97 |
type: str |
| 98 |
description: No description |
| 99 |
type: |
| 100 |
type: str |
| 101 |
description: |
| 102 |
- Type of LDAP binding. |
| 103 |
- simple - Simple password authentication without search. |
| 104 |
- anonymous - Bind using anonymous user search. |
| 105 |
- regular - Bind using username/password and then search. |
| 106 |
choices: ['simple', 'anonymous', 'regular'] |
| 107 |
username: |
| 108 |
type: str |
| 109 |
description: Username |
| 110 |
adom_access: |
| 111 |
aliases: ['adom-access'] |
| 112 |
type: str |
| 113 |
description: |
| 114 |
- set all or specify adom access type. |
| 115 |
- all - All ADOMs access. |
| 116 |
- specify - Specify ADOMs access. |
| 117 |
choices: ['all', 'specify'] |
| 118 |
ssl_protocol: |
| 119 |
aliases: ['ssl-protocol'] |
| 120 |
type: str |
| 121 |
description: |
| 122 |
- set the lowest SSL protocol version for connection to ldap server. |
| 123 |
- follow-global-ssl-protocol - Follow system. |
| 124 |
- sslv3 - set SSLv3 as the lowest version. |
| 125 |
- tlsv1. |
| 126 |
- tlsv1. |
| 127 |
- tlsv1. |
| 128 |
- tlsv1. |
| 129 |
choices: ['follow-global-ssl-protocol', 'sslv3', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', |
| 130 |
'tlsv1.3'] |
| 131 |
''' |
| 132 |
|
| 133 |
EXAMPLES = ''' |
| 134 |
- name: Example playbook |
| 135 |
hosts: fortimanagers |
| 136 |
gather_facts: false |
| 137 |
connection: httpapi |
| 138 |
vars: |
| 139 |
ansible_httpapi_use_ssl: true |
| 140 |
ansible_httpapi_validate_certs: false |
| 141 |
ansible_httpapi_port: 443 |
| 142 |
tasks: |
| 143 |
- name: LDAP server entry configuration. |
| 144 |
fortinet.fortimanager.fmgr_system_admin_ldap: |
| 145 |
bypass_validation: false |
| 146 |
state: present |
| 147 |
system_admin_ldap: |
| 148 |
adom: |
| 149 |
- adom_name: ansible |
| 150 |
name: ansible-test-ldap |
| 151 |
password: Fortinet |
| 152 |
port: 390 |
| 153 |
server: ansible |
| 154 |
type: regular # <value in [simple, anonymous, regular]> |
| 155 |
username: ansible-username |
| 156 |
|
| 157 |
- name: Gathering fortimanager facts |
| 158 |
hosts: fortimanagers |
| 159 |
gather_facts: false |
| 160 |
connection: httpapi |
| 161 |
vars: |
| 162 |
ansible_httpapi_use_ssl: true |
| 163 |
ansible_httpapi_validate_certs: false |
| 164 |
ansible_httpapi_port: 443 |
| 165 |
tasks: |
| 166 |
- name: Retrieve all the LDAP servers |
| 167 |
fortinet.fortimanager.fmgr_fact: |
| 168 |
facts: |
| 169 |
selector: "system_admin_ldap" |
| 170 |
params: |
| 171 |
ldap: "your_value" |
| 172 |
''' |
| 173 |
|
| 174 |
RETURN = ''' |
| 175 |
meta: |
| 176 |
description: The result of the request. |
| 177 |
type: dict |
| 178 |
returned: always |
| 179 |
contains: |
| 180 |
request_url: |
| 181 |
description: The full url requested. |
| 182 |
returned: always |
| 183 |
type: str |
| 184 |
sample: /sys/login/user |
| 185 |
response_code: |
| 186 |
description: The status of api request. |
| 187 |
returned: always |
| 188 |
type: int |
| 189 |
sample: 0 |
| 190 |
response_data: |
| 191 |
description: The api response. |
| 192 |
type: list |
| 193 |
returned: always |
| 194 |
response_message: |
| 195 |
description: The descriptive message of the api response. |
| 196 |
type: str |
| 197 |
returned: always |
| 198 |
sample: OK. |
| 199 |
system_information: |
| 200 |
description: The information of the target system. |
| 201 |
type: dict |
| 202 |
returned: always |
| 203 |
rc: |
| 204 |
description: The status the request. |
| 205 |
type: int |
| 206 |
returned: always |
| 207 |
sample: 0 |
| 208 |
version_check_warning: |
| 209 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 210 |
type: list |
| 211 |
returned: complex |
| 212 |
''' |
| 213 |
from ansible.module_utils.basic import AnsibleModule |
| 214 |
from ansible.module_utils.connection import Connection |
| 215 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 216 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 217 |
|
| 218 |
|
| 219 |
def main(): |
| 220 |
urls_list = [ |
| 221 |
'/cli/global/system/admin/ldap' |
| 222 |
] |
| 223 |
module_arg_spec = { |
| 224 |
'system_admin_ldap': { |
| 225 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 226 |
'options': { |
| 227 |
'adom': {'type': 'list', 'options': {'adom-name': {'type': 'str'}}, 'elements': 'dict'}, |
| 228 |
'adom-attr': {'type': 'str'}, |
| 229 |
'attributes': {'type': 'str'}, |
| 230 |
'ca-cert': {'type': 'str'}, |
| 231 |
'cnid': {'type': 'str'}, |
| 232 |
'connect-timeout': {'v_range': [['6.0.0', '7.2.9'], ['7.4.0', '7.4.2']], 'type': 'int'}, |
| 233 |
'dn': {'type': 'str'}, |
| 234 |
'filter': {'type': 'str'}, |
| 235 |
'group': {'type': 'str'}, |
| 236 |
'memberof-attr': {'type': 'str'}, |
| 237 |
'name': {'required': True, 'type': 'str'}, |
| 238 |
'password': {'no_log': True, 'type': 'raw'}, |
| 239 |
'port': {'type': 'int'}, |
| 240 |
'profile-attr': {'type': 'str'}, |
| 241 |
'secondary-server': {'type': 'str'}, |
| 242 |
'secure': {'choices': ['disable', 'starttls', 'ldaps'], 'type': 'str'}, |
| 243 |
'server': {'type': 'str'}, |
| 244 |
'tertiary-server': {'type': 'str'}, |
| 245 |
'type': {'choices': ['simple', 'anonymous', 'regular'], 'type': 'str'}, |
| 246 |
'username': {'type': 'str'}, |
| 247 |
'adom-access': {'v_range': [['7.0.3', '']], 'choices': ['all', 'specify'], 'type': 'str'}, |
| 248 |
'ssl-protocol': { |
| 249 |
'v_range': [['7.4.4', '7.4.10'], ['7.6.2', '']], |
| 250 |
'choices': ['follow-global-ssl-protocol', 'sslv3', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', 'tlsv1.3'], |
| 251 |
'type': 'str' |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
module_option_spec = get_module_arg_spec('full crud') |
| 258 |
module_arg_spec.update(module_option_spec) |
| 259 |
check_galaxy_version(module_arg_spec) |
| 260 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_admin_ldap'), |
| 261 |
supports_check_mode=True) |
| 262 |
if not module._socket_path: |
| 263 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 264 |
connection = Connection(module._socket_path) |
| 265 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 266 |
'name', 'data', module, connection) |
| 267 |
fmgr.process_crud() |
| 268 |
module.exit_json(meta=module.params) |
| 269 |
|
| 270 |
|
| 271 |
if __name__ == '__main__': |
| 272 |
main() |