2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
2021-08-08 10:40:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright (c) 2018, Stephan Schwarz <stearz@gmx.de>
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: utm_ca_host_key_cert
|
|
|
|
|
|
|
|
author:
|
|
|
|
- Stephan Schwarz (@stearz)
|
|
|
|
|
2022-11-09 21:09:09 +01:00
|
|
|
short_description: Create, update or destroy ca host_key_cert entry in Sophos UTM
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
description:
|
|
|
|
- Create, update or destroy a ca host_key_cert entry in SOPHOS UTM.
|
|
|
|
- This module needs to have the REST Ability of the UTM to be activated.
|
|
|
|
|
2023-02-24 09:23:28 +01:00
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: none
|
|
|
|
diff_mode:
|
|
|
|
support: none
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of the object. Will be used to identify the entry.
|
|
|
|
required: true
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
ca:
|
|
|
|
description:
|
|
|
|
- A reference to an existing utm_ca_signing_ca or utm_ca_verification_ca object.
|
|
|
|
required: true
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
meta:
|
|
|
|
description:
|
|
|
|
- A reference to an existing utm_ca_meta_x509 object.
|
|
|
|
required: true
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
certificate:
|
|
|
|
description:
|
|
|
|
- The certificate in PEM format.
|
|
|
|
required: true
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
comment:
|
|
|
|
description:
|
|
|
|
- Optional comment string.
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
encrypted:
|
|
|
|
description:
|
|
|
|
- Optionally enable encryption.
|
2022-09-06 20:42:17 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
|
|
|
key:
|
|
|
|
description:
|
|
|
|
- Optional private key in PEM format.
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.utm
|
2023-02-24 09:23:28 +01:00
|
|
|
- community.general.attributes
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
2020-05-16 15:07:51 +02:00
|
|
|
- name: Create a ca_host_key_cert entry
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_ca_host_key_cert:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestHostKeyCertEntry
|
|
|
|
ca: REF_ca/signing_ca_OBJECT_STRING
|
|
|
|
meta: REF_ca/meta_x509_OBJECT_STRING
|
|
|
|
certificate: |
|
|
|
|
--- BEGIN CERTIFICATE ---
|
|
|
|
. . .
|
|
|
|
. . .
|
|
|
|
. . .
|
|
|
|
--- END CERTIFICATE ---
|
|
|
|
state: present
|
|
|
|
|
2020-05-16 15:07:51 +02:00
|
|
|
- name: Remove a ca_host_key_cert entry
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_ca_host_key_cert:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestHostKeyCertEntry
|
|
|
|
state: absent
|
|
|
|
|
2020-05-16 15:07:51 +02:00
|
|
|
- name: Read a ca_host_key_cert entry
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_ca_host_key_cert:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestHostKeyCertEntry
|
|
|
|
state: info
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
result:
|
|
|
|
description: The utm object that was created
|
|
|
|
returned: success
|
|
|
|
type: complex
|
|
|
|
contains:
|
|
|
|
_ref:
|
|
|
|
description: The reference name of the object
|
|
|
|
type: str
|
|
|
|
_locked:
|
|
|
|
description: Whether or not the object is currently locked
|
|
|
|
type: bool
|
|
|
|
_type:
|
|
|
|
description: The type of the object
|
|
|
|
type: str
|
|
|
|
name:
|
|
|
|
description: The name of the object
|
|
|
|
type: str
|
|
|
|
ca:
|
|
|
|
description: A reference to an existing utm_ca_signing_ca or utm_ca_verification_ca object.
|
|
|
|
type: str
|
|
|
|
meta:
|
|
|
|
description: A reference to an existing utm_ca_meta_x509 object.
|
|
|
|
type: str
|
|
|
|
certificate:
|
|
|
|
description: The certificate in PEM format
|
|
|
|
type: str
|
|
|
|
comment:
|
|
|
|
description: Comment string (may be empty string)
|
|
|
|
type: str
|
|
|
|
encrypted:
|
|
|
|
description: If encryption is enabled
|
|
|
|
type: bool
|
|
|
|
key:
|
|
|
|
description: Private key in PEM format (may be empty string)
|
|
|
|
type: str
|
|
|
|
"""
|
|
|
|
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.utm_utils import UTM, UTMModule
|
2021-06-26 23:59:11 +02:00
|
|
|
from ansible.module_utils.common.text.converters import to_native
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
endpoint = "ca/host_key_cert"
|
|
|
|
key_to_check_for_changes = ["ca", "certificate", "comment", "encrypted", "key", "meta"]
|
|
|
|
module = UTMModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
name=dict(type='str', required=True),
|
|
|
|
ca=dict(type='str', required=True),
|
|
|
|
meta=dict(type='str', required=True),
|
|
|
|
certificate=dict(type='str', required=True),
|
|
|
|
comment=dict(type='str', required=False),
|
|
|
|
encrypted=dict(type='bool', required=False, default=False),
|
|
|
|
key=dict(type='str', required=False, no_log=True),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
# This is needed because the bool value only accepts int values in the backend
|
|
|
|
UTM(module, endpoint, key_to_check_for_changes).execute()
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg=to_native(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|