| 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_passwordpolicy |
| 15 |
short_description: Password policy. |
| 16 |
version_added: "2.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.partial_crud |
| 20 |
options: |
| 21 |
system_passwordpolicy: |
| 22 |
description: The top level parameters set. |
| 23 |
required: false |
| 24 |
type: dict |
| 25 |
suboptions: |
| 26 |
change_4_characters: |
| 27 |
aliases: ['change-4-characters'] |
| 28 |
type: str |
| 29 |
description: |
| 30 |
- Enable/disable changing at least 4 characters for new password. |
| 31 |
- disable - Disable changing at least 4 characters for new password. |
| 32 |
- enable - Enable changing at least 4 characters for new password. |
| 33 |
choices: ['disable', 'enable'] |
| 34 |
expire: |
| 35 |
type: int |
| 36 |
description: Number of days after which admin users password will expire |
| 37 |
minimum_length: |
| 38 |
aliases: ['minimum-length'] |
| 39 |
type: int |
| 40 |
description: Minimum password length. |
| 41 |
must_contain: |
| 42 |
aliases: ['must-contain'] |
| 43 |
type: list |
| 44 |
elements: str |
| 45 |
description: |
| 46 |
- Password character requirements. |
| 47 |
- upper-case-letter - Require password to contain upper case letter. |
| 48 |
- lower-case-letter - Require password to contain lower case letter. |
| 49 |
- number - Require password to contain number. |
| 50 |
- non-alphanumeric - Require password to contain non-alphanumeric characters. |
| 51 |
choices: ['upper-case-letter', 'lower-case-letter', 'number', 'non-alphanumeric'] |
| 52 |
status: |
| 53 |
type: str |
| 54 |
description: |
| 55 |
- Enable/disable password policy. |
| 56 |
- disable - Disable password policy. |
| 57 |
- enable - Enable password policy. |
| 58 |
choices: ['disable', 'enable'] |
| 59 |
password_history: |
| 60 |
aliases: ['password-history'] |
| 61 |
type: int |
| 62 |
description: Number of unique new passwords that must be used before old password can be reused |
| 63 |
login_lockout_upon_downgrade: |
| 64 |
aliases: ['login-lockout-upon-downgrade'] |
| 65 |
type: str |
| 66 |
description: |
| 67 |
- Enable/disable administrative user login lockout upon downgrade |
| 68 |
- disable - Disable administrative user login lockout upon downgrade. |
| 69 |
- enable - Enable administrative user login lockout upon downgrade. |
| 70 |
choices: ['disable', 'enable'] |
| 71 |
''' |
| 72 |
|
| 73 |
EXAMPLES = ''' |
| 74 |
- name: Example playbook (generated based on argument schema) |
| 75 |
hosts: fortimanagers |
| 76 |
connection: httpapi |
| 77 |
gather_facts: false |
| 78 |
tasks: |
| 79 |
- name: Password policy. |
| 80 |
fortinet.fortimanager.fmgr_system_passwordpolicy: |
| 81 |
# workspace_locking_adom: <global or your adom name> |
| 82 |
system_passwordpolicy: |
| 83 |
# change_4_characters: <value in [disable, enable]> |
| 84 |
# expire: <integer> |
| 85 |
# minimum_length: <integer> |
| 86 |
# must_contain: ["upper-case-letter", "lower-case-letter", "number", "non-alphanumeric"] |
| 87 |
# status: <value in [disable, enable]> |
| 88 |
# password_history: <integer> |
| 89 |
# login_lockout_upon_downgrade: <value in [disable, enable]> |
| 90 |
''' |
| 91 |
|
| 92 |
RETURN = ''' |
| 93 |
meta: |
| 94 |
description: The result of the request. |
| 95 |
type: dict |
| 96 |
returned: always |
| 97 |
contains: |
| 98 |
request_url: |
| 99 |
description: The full url requested. |
| 100 |
returned: always |
| 101 |
type: str |
| 102 |
sample: /sys/login/user |
| 103 |
response_code: |
| 104 |
description: The status of api request. |
| 105 |
returned: always |
| 106 |
type: int |
| 107 |
sample: 0 |
| 108 |
response_data: |
| 109 |
description: The api response. |
| 110 |
type: list |
| 111 |
returned: always |
| 112 |
response_message: |
| 113 |
description: The descriptive message of the api response. |
| 114 |
type: str |
| 115 |
returned: always |
| 116 |
sample: OK. |
| 117 |
system_information: |
| 118 |
description: The information of the target system. |
| 119 |
type: dict |
| 120 |
returned: always |
| 121 |
rc: |
| 122 |
description: The status the request. |
| 123 |
type: int |
| 124 |
returned: always |
| 125 |
sample: 0 |
| 126 |
version_check_warning: |
| 127 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 128 |
type: list |
| 129 |
returned: complex |
| 130 |
''' |
| 131 |
from ansible.module_utils.basic import AnsibleModule |
| 132 |
from ansible.module_utils.connection import Connection |
| 133 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 134 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 135 |
|
| 136 |
|
| 137 |
def main(): |
| 138 |
urls_list = [ |
| 139 |
'/cli/global/system/password-policy' |
| 140 |
] |
| 141 |
module_arg_spec = { |
| 142 |
'system_passwordpolicy': { |
| 143 |
'type': 'dict', 'v_range': [['6.0.0', '']], 'no_log': False, |
| 144 |
'options': { |
| 145 |
'change-4-characters': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 146 |
'expire': {'type': 'int'}, |
| 147 |
'minimum-length': {'type': 'int'}, |
| 148 |
'must-contain': {'type': 'list', 'choices': ['upper-case-letter', 'lower-case-letter', 'number', 'non-alphanumeric'], 'elements': 'str'}, |
| 149 |
'status': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 150 |
'password-history': {'v_range': [['7.6.0', '']], 'no_log': True, 'type': 'int'}, |
| 151 |
'login-lockout-upon-downgrade': { |
| 152 |
'v_range': [['7.2.11', '7.2.12'], ['7.4.7', '7.4.10'], ['7.6.3', '']], |
| 153 |
'choices': ['disable', 'enable'], |
| 154 |
'type': 'str' |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
module_option_spec = get_module_arg_spec('partial crud') |
| 161 |
module_arg_spec.update(module_option_spec) |
| 162 |
check_galaxy_version(module_arg_spec) |
| 163 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_passwordpolicy'), |
| 164 |
supports_check_mode=True) |
| 165 |
if not module._socket_path: |
| 166 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 167 |
connection = Connection(module._socket_path) |
| 168 |
fmgr = NAPIManager('partial crud', module_arg_spec, urls_list, |
| 169 |
None, 'data', module, connection) |
| 170 |
fmgr.process_partial_crud() |
| 171 |
module.exit_json(meta=module.params) |
| 172 |
|
| 173 |
|
| 174 |
if __name__ == '__main__': |
| 175 |
main() |