| 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_certificate_template |
| 15 |
short_description: Certificate template |
| 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 |
certificate_template: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
city: |
| 34 |
type: str |
| 35 |
description: City. |
| 36 |
country: |
| 37 |
type: str |
| 38 |
description: Country. |
| 39 |
digest_type: |
| 40 |
aliases: ['digest-type'] |
| 41 |
type: str |
| 42 |
description: Digest type. |
| 43 |
choices: ['sha1', 'sha256'] |
| 44 |
email: |
| 45 |
type: str |
| 46 |
description: Email. |
| 47 |
id_type: |
| 48 |
aliases: ['id-type'] |
| 49 |
type: str |
| 50 |
description: Id type. |
| 51 |
choices: ['host-ip', 'domain-name', 'email'] |
| 52 |
key_size: |
| 53 |
aliases: ['key-size'] |
| 54 |
type: str |
| 55 |
description: Key size. |
| 56 |
choices: ['512', '1024', '1536', '2048', '4096'] |
| 57 |
key_type: |
| 58 |
aliases: ['key-type'] |
| 59 |
type: str |
| 60 |
description: Key type. |
| 61 |
choices: ['rsa', 'ec'] |
| 62 |
name: |
| 63 |
type: str |
| 64 |
description: Name. |
| 65 |
required: true |
| 66 |
organization: |
| 67 |
type: str |
| 68 |
description: Organization. |
| 69 |
organization_unit: |
| 70 |
aliases: ['organization-unit'] |
| 71 |
type: raw |
| 72 |
description: (list) Organization unit. |
| 73 |
scep_password: |
| 74 |
aliases: ['scep-password'] |
| 75 |
type: raw |
| 76 |
description: (list) Scep password. |
| 77 |
scep_server: |
| 78 |
aliases: ['scep-server'] |
| 79 |
type: str |
| 80 |
description: Scep server. |
| 81 |
state: |
| 82 |
type: str |
| 83 |
description: State. |
| 84 |
subject_name: |
| 85 |
aliases: ['subject-name'] |
| 86 |
type: str |
| 87 |
description: Subject name. |
| 88 |
type: |
| 89 |
type: str |
| 90 |
description: Type. |
| 91 |
choices: ['external', 'local'] |
| 92 |
curve_name: |
| 93 |
aliases: ['curve-name'] |
| 94 |
type: str |
| 95 |
description: Curve name. |
| 96 |
choices: ['secp256r1', 'secp384r1', 'secp521r1'] |
| 97 |
scep_ca_identifier: |
| 98 |
aliases: ['scep-ca-identifier'] |
| 99 |
type: str |
| 100 |
description: Scep ca identifier. |
| 101 |
subject_alt_name: |
| 102 |
aliases: ['subject-alt-name'] |
| 103 |
type: str |
| 104 |
description: Support meta variable |
| 105 |
''' |
| 106 |
|
| 107 |
EXAMPLES = ''' |
| 108 |
- name: Example playbook |
| 109 |
hosts: fortimanagers |
| 110 |
gather_facts: false |
| 111 |
connection: httpapi |
| 112 |
vars: |
| 113 |
ansible_httpapi_use_ssl: true |
| 114 |
ansible_httpapi_validate_certs: false |
| 115 |
ansible_httpapi_port: 443 |
| 116 |
tasks: |
| 117 |
- name: No description |
| 118 |
fortinet.fortimanager.fmgr_certificate_template: |
| 119 |
adom: ansible |
| 120 |
state: present |
| 121 |
certificate_template: |
| 122 |
# digest_type: sha1 |
| 123 |
id_type: host-ip |
| 124 |
key_size: 512 |
| 125 |
key_type: rsa |
| 126 |
name: "ansible-test" |
| 127 |
scep_password: "fortinet1" |
| 128 |
type: external |
| 129 |
|
| 130 |
- name: Gathering fortimanager facts |
| 131 |
hosts: fortimanagers |
| 132 |
gather_facts: false |
| 133 |
connection: httpapi |
| 134 |
vars: |
| 135 |
ansible_httpapi_use_ssl: true |
| 136 |
ansible_httpapi_validate_certs: false |
| 137 |
ansible_httpapi_port: 443 |
| 138 |
tasks: |
| 139 |
- name: Retrieve all the scripts |
| 140 |
fortinet.fortimanager.fmgr_fact: |
| 141 |
facts: |
| 142 |
selector: "certificate_template" |
| 143 |
params: |
| 144 |
adom: "ansible" |
| 145 |
template: "your_value" |
| 146 |
''' |
| 147 |
|
| 148 |
RETURN = ''' |
| 149 |
meta: |
| 150 |
description: The result of the request. |
| 151 |
type: dict |
| 152 |
returned: always |
| 153 |
contains: |
| 154 |
request_url: |
| 155 |
description: The full url requested. |
| 156 |
returned: always |
| 157 |
type: str |
| 158 |
sample: /sys/login/user |
| 159 |
response_code: |
| 160 |
description: The status of api request. |
| 161 |
returned: always |
| 162 |
type: int |
| 163 |
sample: 0 |
| 164 |
response_data: |
| 165 |
description: The api response. |
| 166 |
type: list |
| 167 |
returned: always |
| 168 |
response_message: |
| 169 |
description: The descriptive message of the api response. |
| 170 |
type: str |
| 171 |
returned: always |
| 172 |
sample: OK. |
| 173 |
system_information: |
| 174 |
description: The information of the target system. |
| 175 |
type: dict |
| 176 |
returned: always |
| 177 |
rc: |
| 178 |
description: The status the request. |
| 179 |
type: int |
| 180 |
returned: always |
| 181 |
sample: 0 |
| 182 |
version_check_warning: |
| 183 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 184 |
type: list |
| 185 |
returned: complex |
| 186 |
''' |
| 187 |
from ansible.module_utils.basic import AnsibleModule |
| 188 |
from ansible.module_utils.connection import Connection |
| 189 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 190 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 191 |
|
| 192 |
|
| 193 |
def main(): |
| 194 |
urls_list = [ |
| 195 |
'/pm/config/adom/{adom}/obj/certificate/template', |
| 196 |
'/pm/config/global/obj/certificate/template' |
| 197 |
] |
| 198 |
module_arg_spec = { |
| 199 |
'adom': {'required': True, 'type': 'str'}, |
| 200 |
'revision_note': {'type': 'str'}, |
| 201 |
'certificate_template': { |
| 202 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 203 |
'options': { |
| 204 |
'city': {'type': 'str'}, |
| 205 |
'country': {'type': 'str'}, |
| 206 |
'digest-type': {'choices': ['sha1', 'sha256'], 'type': 'str'}, |
| 207 |
'email': {'type': 'str'}, |
| 208 |
'id-type': {'choices': ['host-ip', 'domain-name', 'email'], 'type': 'str'}, |
| 209 |
'key-size': {'choices': ['512', '1024', '1536', '2048', '4096'], 'type': 'str'}, |
| 210 |
'key-type': {'choices': ['rsa', 'ec'], 'type': 'str'}, |
| 211 |
'name': {'required': True, 'type': 'str'}, |
| 212 |
'organization': {'type': 'str'}, |
| 213 |
'organization-unit': {'type': 'raw'}, |
| 214 |
'scep-password': {'no_log': True, 'type': 'raw'}, |
| 215 |
'scep-server': {'type': 'str'}, |
| 216 |
'state': {'type': 'str'}, |
| 217 |
'subject-name': {'type': 'str'}, |
| 218 |
'type': {'choices': ['external', 'local'], 'type': 'str'}, |
| 219 |
'curve-name': {'v_range': [['6.2.1', '']], 'choices': ['secp256r1', 'secp384r1', 'secp521r1'], 'type': 'str'}, |
| 220 |
'scep-ca-identifier': {'v_range': [['7.0.4', '']], 'type': 'str'}, |
| 221 |
'subject-alt-name': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'str'} |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
module_option_spec = get_module_arg_spec('full crud') |
| 227 |
module_arg_spec.update(module_option_spec) |
| 228 |
check_galaxy_version(module_arg_spec) |
| 229 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'certificate_template'), |
| 230 |
supports_check_mode=True) |
| 231 |
if not module._socket_path: |
| 232 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 233 |
connection = Connection(module._socket_path) |
| 234 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 235 |
'name', 'data', module, connection) |
| 236 |
fmgr.process_crud() |
| 237 |
module.exit_json(meta=module.params) |
| 238 |
|
| 239 |
|
| 240 |
if __name__ == '__main__': |
| 241 |
main() |