| 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_vpn_certificate_hsmlocal |
| 15 |
short_description: Local certificates whose keys are stored on HSM. |
| 16 |
version_added: "2.12.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 |
vpn_certificate_hsmlocal: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
api_version: |
| 34 |
aliases: ['api-version'] |
| 35 |
type: str |
| 36 |
description: API version for communicating with HSM. |
| 37 |
choices: ['unknown', 'gch-default'] |
| 38 |
certificate: |
| 39 |
type: str |
| 40 |
description: PEM format certificate. |
| 41 |
comments: |
| 42 |
type: str |
| 43 |
description: Comment. |
| 44 |
gch_cloud_service_name: |
| 45 |
aliases: ['gch-cloud-service-name'] |
| 46 |
type: list |
| 47 |
elements: str |
| 48 |
description: Cloud service config name to generate access token. |
| 49 |
gch_cryptokey: |
| 50 |
aliases: ['gch-cryptokey'] |
| 51 |
type: str |
| 52 |
description: Google Cloud HSM cryptokey. |
| 53 |
gch_cryptokey_algorithm: |
| 54 |
aliases: ['gch-cryptokey-algorithm'] |
| 55 |
type: str |
| 56 |
description: Google Cloud HSM cryptokey algorithm. |
| 57 |
choices: ['rsa-sign-pkcs1-2048-sha256', 'rsa-sign-pkcs1-3072-sha256', |
| 58 |
'rsa-sign-pkcs1-4096-sha256', 'rsa-sign-pkcs1-4096-sha512', |
| 59 |
'rsa-sign-pss-2048-sha256', 'rsa-sign-pss-3072-sha256', |
| 60 |
'rsa-sign-pss-4096-sha256', 'rsa-sign-pss-4096-sha512', |
| 61 |
'ec-sign-p256-sha256', 'ec-sign-p384-sha384', |
| 62 |
'ec-sign-secp256k1-sha256', '2048-RSA-PKCS1v1.5-SHA256', |
| 63 |
'3072-RSA-PKCS1v1.5-SHA256', '4096-RSA-PKCS1v1.5-SHA256', |
| 64 |
'4096-RSA-PKCS1v1.5-SHA512', 'EC_P256_SHA256', 'EC_P384_SHA384', |
| 65 |
'EC_secp256k1_SHA256'] |
| 66 |
gch_cryptokey_version: |
| 67 |
aliases: ['gch-cryptokey-version'] |
| 68 |
type: str |
| 69 |
description: Google Cloud HSM cryptokey version. |
| 70 |
gch_keyring: |
| 71 |
aliases: ['gch-keyring'] |
| 72 |
type: str |
| 73 |
description: Google Cloud HSM keyring. |
| 74 |
gch_location: |
| 75 |
aliases: ['gch-location'] |
| 76 |
type: str |
| 77 |
description: Google Cloud HSM location. |
| 78 |
gch_project: |
| 79 |
aliases: ['gch-project'] |
| 80 |
type: str |
| 81 |
description: Google Cloud HSM project ID. |
| 82 |
gch_url: |
| 83 |
aliases: ['gch-url'] |
| 84 |
type: str |
| 85 |
description: Gch url. |
| 86 |
name: |
| 87 |
type: str |
| 88 |
description: Name. |
| 89 |
required: true |
| 90 |
range: |
| 91 |
type: str |
| 92 |
description: Either a global or VDOM IP address range for the certificate. |
| 93 |
choices: ['global', 'vdom'] |
| 94 |
source: |
| 95 |
type: str |
| 96 |
description: Certificate source type. |
| 97 |
choices: ['factory', 'user', 'bundle'] |
| 98 |
tmp_cert_file: |
| 99 |
aliases: ['tmp-cert-file'] |
| 100 |
type: str |
| 101 |
description: Temporary certificate file. |
| 102 |
vendor: |
| 103 |
type: str |
| 104 |
description: HSM vendor. |
| 105 |
choices: ['unknown', 'gch'] |
| 106 |
''' |
| 107 |
|
| 108 |
EXAMPLES = ''' |
| 109 |
- name: Example playbook (generated based on argument schema) |
| 110 |
hosts: fortimanagers |
| 111 |
connection: httpapi |
| 112 |
gather_facts: false |
| 113 |
tasks: |
| 114 |
- name: Local certificates whose keys are stored on HSM. |
| 115 |
fortinet.fortimanager.fmgr_vpn_certificate_hsmlocal: |
| 116 |
# workspace_locking_adom: <global or your adom name> |
| 117 |
adom: <your own value> |
| 118 |
state: present # <value in [present, absent]> |
| 119 |
vpn_certificate_hsmlocal: |
| 120 |
name: "your value" # Required variable, string |
| 121 |
# api_version: <value in [unknown, gch-default]> |
| 122 |
# certificate: <string> |
| 123 |
# comments: <string> |
| 124 |
# gch_cloud_service_name: <list or string> |
| 125 |
# gch_cryptokey: <string> |
| 126 |
# gch_cryptokey_algorithm: <value in [rsa-sign-pkcs1-2048-sha256, rsa-sign-pkcs1-3072-sha256, rsa-sign-pkcs1-4096-sha256, ...]> |
| 127 |
# gch_cryptokey_version: <string> |
| 128 |
# gch_keyring: <string> |
| 129 |
# gch_location: <string> |
| 130 |
# gch_project: <string> |
| 131 |
# gch_url: <string> |
| 132 |
# range: <value in [global, vdom]> |
| 133 |
# source: <value in [factory, user, bundle]> |
| 134 |
# tmp_cert_file: <string> |
| 135 |
# vendor: <value in [unknown, gch]> |
| 136 |
''' |
| 137 |
|
| 138 |
RETURN = ''' |
| 139 |
meta: |
| 140 |
description: The result of the request. |
| 141 |
type: dict |
| 142 |
returned: always |
| 143 |
contains: |
| 144 |
request_url: |
| 145 |
description: The full url requested. |
| 146 |
returned: always |
| 147 |
type: str |
| 148 |
sample: /sys/login/user |
| 149 |
response_code: |
| 150 |
description: The status of api request. |
| 151 |
returned: always |
| 152 |
type: int |
| 153 |
sample: 0 |
| 154 |
response_data: |
| 155 |
description: The api response. |
| 156 |
type: list |
| 157 |
returned: always |
| 158 |
response_message: |
| 159 |
description: The descriptive message of the api response. |
| 160 |
type: str |
| 161 |
returned: always |
| 162 |
sample: OK. |
| 163 |
system_information: |
| 164 |
description: The information of the target system. |
| 165 |
type: dict |
| 166 |
returned: always |
| 167 |
rc: |
| 168 |
description: The status the request. |
| 169 |
type: int |
| 170 |
returned: always |
| 171 |
sample: 0 |
| 172 |
version_check_warning: |
| 173 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 174 |
type: list |
| 175 |
returned: complex |
| 176 |
''' |
| 177 |
from ansible.module_utils.basic import AnsibleModule |
| 178 |
from ansible.module_utils.connection import Connection |
| 179 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 180 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 181 |
|
| 182 |
|
| 183 |
def main(): |
| 184 |
urls_list = [ |
| 185 |
'/pm/config/adom/{adom}/obj/vpn/certificate/hsm-local', |
| 186 |
'/pm/config/global/obj/vpn/certificate/hsm-local' |
| 187 |
] |
| 188 |
module_arg_spec = { |
| 189 |
'adom': {'required': True, 'type': 'str'}, |
| 190 |
'revision_note': {'type': 'str'}, |
| 191 |
'vpn_certificate_hsmlocal': { |
| 192 |
'type': 'dict', 'v_range': [['7.6.4', '']], |
| 193 |
'options': { |
| 194 |
'api-version': {'v_range': [['7.6.4', '']], 'choices': ['unknown', 'gch-default'], 'type': 'str'}, |
| 195 |
'certificate': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 196 |
'comments': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 197 |
'gch-cloud-service-name': {'v_range': [['7.6.4', '']], 'type': 'list', 'elements': 'str'}, |
| 198 |
'gch-cryptokey': {'v_range': [['7.6.4', '']], 'no_log': True, 'type': 'str'}, |
| 199 |
'gch-cryptokey-algorithm': { |
| 200 |
'v_range': [['7.6.4', '']], |
| 201 |
'choices': [ |
| 202 |
'rsa-sign-pkcs1-2048-sha256', 'rsa-sign-pkcs1-3072-sha256', 'rsa-sign-pkcs1-4096-sha256', 'rsa-sign-pkcs1-4096-sha512', |
| 203 |
'rsa-sign-pss-2048-sha256', 'rsa-sign-pss-3072-sha256', 'rsa-sign-pss-4096-sha256', 'rsa-sign-pss-4096-sha512', |
| 204 |
'ec-sign-p256-sha256', 'ec-sign-p384-sha384', 'ec-sign-secp256k1-sha256', '2048-RSA-PKCS1v1.5-SHA256', |
| 205 |
'3072-RSA-PKCS1v1.5-SHA256', '4096-RSA-PKCS1v1.5-SHA256', '4096-RSA-PKCS1v1.5-SHA512', 'EC_P256_SHA256', 'EC_P384_SHA384', |
| 206 |
'EC_secp256k1_SHA256' |
| 207 |
], |
| 208 |
'type': 'str' |
| 209 |
}, |
| 210 |
'gch-cryptokey-version': {'v_range': [['7.6.4', '']], 'no_log': True, 'type': 'str'}, |
| 211 |
'gch-keyring': {'v_range': [['7.6.4', '']], 'no_log': True, 'type': 'str'}, |
| 212 |
'gch-location': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 213 |
'gch-project': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 214 |
'gch-url': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 215 |
'name': {'v_range': [['7.6.4', '']], 'required': True, 'type': 'str'}, |
| 216 |
'range': {'v_range': [['7.6.4', '']], 'choices': ['global', 'vdom'], 'type': 'str'}, |
| 217 |
'source': {'v_range': [['7.6.4', '']], 'choices': ['factory', 'user', 'bundle'], 'type': 'str'}, |
| 218 |
'tmp-cert-file': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 219 |
'vendor': {'v_range': [['7.6.4', '']], 'choices': ['unknown', 'gch'], 'type': 'str'} |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
module_option_spec = get_module_arg_spec('full crud') |
| 225 |
module_arg_spec.update(module_option_spec) |
| 226 |
check_galaxy_version(module_arg_spec) |
| 227 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'vpn_certificate_hsmlocal'), |
| 228 |
supports_check_mode=True) |
| 229 |
if not module._socket_path: |
| 230 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 231 |
connection = Connection(module._socket_path) |
| 232 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 233 |
'name', 'data', module, connection) |
| 234 |
fmgr.process_crud() |
| 235 |
module.exit_json(meta=module.params) |
| 236 |
|
| 237 |
|
| 238 |
if __name__ == '__main__': |
| 239 |
main() |