| 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_local |
| 15 |
short_description: Configure local 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_local: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
auth_concurrent_override: |
| 34 |
aliases: ['auth-concurrent-override'] |
| 35 |
type: str |
| 36 |
description: Enable/disable overriding the policy-auth-concurrent under config system global. |
| 37 |
choices: ['disable', 'enable'] |
| 38 |
auth_concurrent_value: |
| 39 |
aliases: ['auth-concurrent-value'] |
| 40 |
type: int |
| 41 |
description: Maximum number of concurrent logins permitted from the same user. |
| 42 |
authtimeout: |
| 43 |
type: int |
| 44 |
description: Time in minutes before the authentication timeout for a user is reached. |
| 45 |
email_to: |
| 46 |
aliases: ['email-to'] |
| 47 |
type: str |
| 48 |
description: Two-factor recipients email address. |
| 49 |
fortitoken: |
| 50 |
type: str |
| 51 |
description: Two-factor recipients FortiToken serial number. |
| 52 |
id: |
| 53 |
type: int |
| 54 |
description: User ID. |
| 55 |
ldap_server: |
| 56 |
aliases: ['ldap-server'] |
| 57 |
type: str |
| 58 |
description: Name of LDAP server with which the user must authenticate. |
| 59 |
name: |
| 60 |
type: str |
| 61 |
description: User name. |
| 62 |
required: true |
| 63 |
passwd: |
| 64 |
type: raw |
| 65 |
description: (list) Users password. |
| 66 |
passwd_policy: |
| 67 |
aliases: ['passwd-policy'] |
| 68 |
type: str |
| 69 |
description: Password policy to apply to this user, as defined in config user password-policy. |
| 70 |
ppk_identity: |
| 71 |
aliases: ['ppk-identity'] |
| 72 |
type: str |
| 73 |
description: IKEv2 Postquantum Preshared Key Identity. |
| 74 |
ppk_secret: |
| 75 |
aliases: ['ppk-secret'] |
| 76 |
type: raw |
| 77 |
description: (list) IKEv2 Postquantum Preshared Key |
| 78 |
radius_server: |
| 79 |
aliases: ['radius-server'] |
| 80 |
type: str |
| 81 |
description: Name of RADIUS server with which the user must authenticate. |
| 82 |
sms_custom_server: |
| 83 |
aliases: ['sms-custom-server'] |
| 84 |
type: str |
| 85 |
description: Two-factor recipients SMS server. |
| 86 |
sms_phone: |
| 87 |
aliases: ['sms-phone'] |
| 88 |
type: str |
| 89 |
description: Two-factor recipients mobile phone number. |
| 90 |
sms_server: |
| 91 |
aliases: ['sms-server'] |
| 92 |
type: str |
| 93 |
description: Send SMS through FortiGuard or other external server. |
| 94 |
choices: ['fortiguard', 'custom'] |
| 95 |
status: |
| 96 |
type: str |
| 97 |
description: Enable/disable allowing the local user to authenticate with the FortiGate unit. |
| 98 |
choices: ['disable', 'enable'] |
| 99 |
tacacs__server: |
| 100 |
aliases: ['tacacs+-server'] |
| 101 |
type: str |
| 102 |
description: Name of TACACS+ server with which the user must authenticate. |
| 103 |
two_factor: |
| 104 |
aliases: ['two-factor'] |
| 105 |
type: str |
| 106 |
description: Enable/disable two-factor authentication. |
| 107 |
choices: ['disable', 'fortitoken', 'email', 'sms', 'fortitoken-cloud'] |
| 108 |
type: |
| 109 |
type: str |
| 110 |
description: Authentication method. |
| 111 |
choices: ['password', 'radius', 'tacacs+', 'ldap', 'saml'] |
| 112 |
workstation: |
| 113 |
type: str |
| 114 |
description: Name of the remote user workstation, if you want to limit the user to authenticate only from a particular workstation. |
| 115 |
two_factor_authentication: |
| 116 |
aliases: ['two-factor-authentication'] |
| 117 |
type: str |
| 118 |
description: Authentication method by FortiToken Cloud. |
| 119 |
choices: ['fortitoken', 'email', 'sms'] |
| 120 |
two_factor_notification: |
| 121 |
aliases: ['two-factor-notification'] |
| 122 |
type: str |
| 123 |
description: Notification method for user activation by FortiToken Cloud. |
| 124 |
choices: ['email', 'sms'] |
| 125 |
username_case_sensitivity: |
| 126 |
aliases: ['username-case-sensitivity'] |
| 127 |
type: str |
| 128 |
description: Enable/disable case sensitivity when performing username matching |
| 129 |
choices: ['disable', 'enable'] |
| 130 |
username_case_insensitivity: |
| 131 |
aliases: ['username-case-insensitivity'] |
| 132 |
type: str |
| 133 |
description: Enable/disable case sensitivity when performing username matching |
| 134 |
choices: ['disable', 'enable'] |
| 135 |
username_sensitivity: |
| 136 |
aliases: ['username-sensitivity'] |
| 137 |
type: str |
| 138 |
description: Enable/disable case and accent sensitivity when performing username matching |
| 139 |
choices: ['disable', 'enable'] |
| 140 |
history0: |
| 141 |
type: raw |
| 142 |
description: (list) History0. |
| 143 |
history1: |
| 144 |
type: raw |
| 145 |
description: (list) History1. |
| 146 |
qkd_profile: |
| 147 |
aliases: ['qkd-profile'] |
| 148 |
type: str |
| 149 |
description: Quantum Key Distribution |
| 150 |
saml_server: |
| 151 |
aliases: ['saml-server'] |
| 152 |
type: raw |
| 153 |
description: (list) Name of SAML server with which the user must authenticate. |
| 154 |
history10: |
| 155 |
type: raw |
| 156 |
description: (list) History10. |
| 157 |
history11: |
| 158 |
type: raw |
| 159 |
description: (list) History11. |
| 160 |
history12: |
| 161 |
type: raw |
| 162 |
description: (list) History12. |
| 163 |
history13: |
| 164 |
type: raw |
| 165 |
description: (list) History13. |
| 166 |
history14: |
| 167 |
type: raw |
| 168 |
description: (list) History14. |
| 169 |
history15: |
| 170 |
type: raw |
| 171 |
description: (list) History15. |
| 172 |
history16: |
| 173 |
type: raw |
| 174 |
description: (list) History16. |
| 175 |
history17: |
| 176 |
type: raw |
| 177 |
description: (list) History17. |
| 178 |
history18: |
| 179 |
type: raw |
| 180 |
description: (list) History18. |
| 181 |
history19: |
| 182 |
type: raw |
| 183 |
description: (list) History19. |
| 184 |
history2: |
| 185 |
type: raw |
| 186 |
description: (list) History2. |
| 187 |
history3: |
| 188 |
type: raw |
| 189 |
description: (list) History3. |
| 190 |
history4: |
| 191 |
type: raw |
| 192 |
description: (list) History4. |
| 193 |
history5: |
| 194 |
type: raw |
| 195 |
description: (list) History5. |
| 196 |
history6: |
| 197 |
type: raw |
| 198 |
description: (list) History6. |
| 199 |
history7: |
| 200 |
type: raw |
| 201 |
description: (list) History7. |
| 202 |
history8: |
| 203 |
type: raw |
| 204 |
description: (list) History8. |
| 205 |
history9: |
| 206 |
type: raw |
| 207 |
description: (list) History9. |
| 208 |
''' |
| 209 |
|
| 210 |
EXAMPLES = ''' |
| 211 |
- name: Example playbook |
| 212 |
hosts: fortimanagers |
| 213 |
gather_facts: false |
| 214 |
connection: httpapi |
| 215 |
vars: |
| 216 |
ansible_httpapi_use_ssl: true |
| 217 |
ansible_httpapi_validate_certs: false |
| 218 |
ansible_httpapi_port: 443 |
| 219 |
tasks: |
| 220 |
- name: Configure local users. |
| 221 |
fortinet.fortimanager.fmgr_user_local: |
| 222 |
bypass_validation: false |
| 223 |
adom: ansible |
| 224 |
state: present |
| 225 |
user_local: |
| 226 |
id: 1 |
| 227 |
name: ansible-test-local |
| 228 |
passwd: fortinet |
| 229 |
status: disable |
| 230 |
|
| 231 |
- name: Gathering fortimanager facts |
| 232 |
hosts: fortimanagers |
| 233 |
gather_facts: false |
| 234 |
connection: httpapi |
| 235 |
vars: |
| 236 |
ansible_httpapi_use_ssl: true |
| 237 |
ansible_httpapi_validate_certs: false |
| 238 |
ansible_httpapi_port: 443 |
| 239 |
tasks: |
| 240 |
- name: Retrieve all the local users |
| 241 |
fortinet.fortimanager.fmgr_fact: |
| 242 |
facts: |
| 243 |
selector: "user_local" |
| 244 |
params: |
| 245 |
adom: "ansible" |
| 246 |
local: "your_value" |
| 247 |
''' |
| 248 |
|
| 249 |
RETURN = ''' |
| 250 |
meta: |
| 251 |
description: The result of the request. |
| 252 |
type: dict |
| 253 |
returned: always |
| 254 |
contains: |
| 255 |
request_url: |
| 256 |
description: The full url requested. |
| 257 |
returned: always |
| 258 |
type: str |
| 259 |
sample: /sys/login/user |
| 260 |
response_code: |
| 261 |
description: The status of api request. |
| 262 |
returned: always |
| 263 |
type: int |
| 264 |
sample: 0 |
| 265 |
response_data: |
| 266 |
description: The api response. |
| 267 |
type: list |
| 268 |
returned: always |
| 269 |
response_message: |
| 270 |
description: The descriptive message of the api response. |
| 271 |
type: str |
| 272 |
returned: always |
| 273 |
sample: OK. |
| 274 |
system_information: |
| 275 |
description: The information of the target system. |
| 276 |
type: dict |
| 277 |
returned: always |
| 278 |
rc: |
| 279 |
description: The status the request. |
| 280 |
type: int |
| 281 |
returned: always |
| 282 |
sample: 0 |
| 283 |
version_check_warning: |
| 284 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 285 |
type: list |
| 286 |
returned: complex |
| 287 |
''' |
| 288 |
from ansible.module_utils.basic import AnsibleModule |
| 289 |
from ansible.module_utils.connection import Connection |
| 290 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 291 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 292 |
|
| 293 |
|
| 294 |
def main(): |
| 295 |
urls_list = [ |
| 296 |
'/pm/config/adom/{adom}/obj/user/local', |
| 297 |
'/pm/config/global/obj/user/local' |
| 298 |
] |
| 299 |
module_arg_spec = { |
| 300 |
'adom': {'required': True, 'type': 'str'}, |
| 301 |
'revision_note': {'type': 'str'}, |
| 302 |
'user_local': { |
| 303 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 304 |
'options': { |
| 305 |
'auth-concurrent-override': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 306 |
'auth-concurrent-value': {'type': 'int'}, |
| 307 |
'authtimeout': {'type': 'int'}, |
| 308 |
'email-to': {'type': 'str'}, |
| 309 |
'fortitoken': {'no_log': True, 'type': 'str'}, |
| 310 |
'id': {'type': 'int'}, |
| 311 |
'ldap-server': {'type': 'str'}, |
| 312 |
'name': {'required': True, 'type': 'str'}, |
| 313 |
'passwd': {'no_log': True, 'type': 'raw'}, |
| 314 |
'passwd-policy': {'no_log': True, 'type': 'str'}, |
| 315 |
'ppk-identity': {'type': 'str'}, |
| 316 |
'ppk-secret': {'no_log': True, 'type': 'raw'}, |
| 317 |
'radius-server': {'type': 'str'}, |
| 318 |
'sms-custom-server': {'type': 'str'}, |
| 319 |
'sms-phone': {'type': 'str'}, |
| 320 |
'sms-server': {'choices': ['fortiguard', 'custom'], 'type': 'str'}, |
| 321 |
'status': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 322 |
'tacacs+-server': {'type': 'str'}, |
| 323 |
'two-factor': {'choices': ['disable', 'fortitoken', 'email', 'sms', 'fortitoken-cloud'], 'type': 'str'}, |
| 324 |
'type': {'choices': ['password', 'radius', 'tacacs+', 'ldap', 'saml'], 'type': 'str'}, |
| 325 |
'workstation': {'type': 'str'}, |
| 326 |
'two-factor-authentication': {'v_range': [['6.2.5', '']], 'choices': ['fortitoken', 'email', 'sms'], 'type': 'str'}, |
| 327 |
'two-factor-notification': {'v_range': [['6.2.5', '']], 'choices': ['email', 'sms'], 'type': 'str'}, |
| 328 |
'username-case-sensitivity': {'v_range': [['6.2.5', '6.2.13'], ['6.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 329 |
'username-case-insensitivity': {'v_range': [['6.4.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 330 |
'username-sensitivity': { |
| 331 |
'v_range': [['6.2.9', '6.2.13'], ['6.4.7', '6.4.15'], ['7.0.1', '']], |
| 332 |
'choices': ['disable', 'enable'], |
| 333 |
'type': 'str' |
| 334 |
}, |
| 335 |
'history0': {'v_range': [['7.4.1', '']], 'type': 'raw'}, |
| 336 |
'history1': {'v_range': [['7.4.1', '']], 'type': 'raw'}, |
| 337 |
'qkd-profile': {'v_range': [['7.4.2', '']], 'type': 'str'}, |
| 338 |
'saml-server': {'v_range': [['7.6.3', '']], 'type': 'raw'}, |
| 339 |
'history10': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 340 |
'history11': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 341 |
'history12': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 342 |
'history13': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 343 |
'history14': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 344 |
'history15': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 345 |
'history16': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 346 |
'history17': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 347 |
'history18': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 348 |
'history19': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 349 |
'history2': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 350 |
'history3': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 351 |
'history4': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 352 |
'history5': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 353 |
'history6': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 354 |
'history7': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 355 |
'history8': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 356 |
'history9': {'v_range': [['7.6.4', '']], 'type': 'raw'} |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
module_option_spec = get_module_arg_spec('full crud') |
| 362 |
module_arg_spec.update(module_option_spec) |
| 363 |
check_galaxy_version(module_arg_spec) |
| 364 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'user_local'), |
| 365 |
supports_check_mode=True) |
| 366 |
if not module._socket_path: |
| 367 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 368 |
connection = Connection(module._socket_path) |
| 369 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 370 |
'name', 'data', module, connection) |
| 371 |
fmgr.process_crud() |
| 372 |
module.exit_json(meta=module.params) |
| 373 |
|
| 374 |
|
| 375 |
if __name__ == '__main__': |
| 376 |
main() |