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 13:17:19 +02:00
|
|
|
# Copyright (c) 2018, Johannes Brunswicker <johannes.brunswicker@gmail.com>
|
|
|
|
# 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_dns_host
|
|
|
|
|
|
|
|
author:
|
|
|
|
- Johannes Brunswicker (@MatrixCrawler)
|
|
|
|
|
|
|
|
short_description: create, update or destroy dns entry in Sophos UTM
|
|
|
|
|
|
|
|
description:
|
|
|
|
- Create, update or destroy a dns entry in SOPHOS UTM.
|
|
|
|
- This module needs to have the REST Ability of the UTM to be activated.
|
|
|
|
|
|
|
|
|
|
|
|
options:
|
|
|
|
name:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The name of the object. Will be used to identify the entry
|
|
|
|
required: true
|
|
|
|
address:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The IPV4 Address of the entry. Can be left empty for automatic resolving.
|
|
|
|
default: 0.0.0.0
|
|
|
|
address6:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The IPV6 Address of the entry. Can be left empty for automatic resolving.
|
|
|
|
default: "::"
|
|
|
|
comment:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- An optional comment to add to the dns host object
|
2022-11-01 19:45:37 +01:00
|
|
|
default: ''
|
2020-03-09 10:11:07 +01:00
|
|
|
hostname:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The hostname for the dns host object
|
|
|
|
interface:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The reference name of the interface to use. If not provided the default interface will be used
|
2022-11-01 19:45:37 +01:00
|
|
|
default: ''
|
2020-03-09 10:11:07 +01:00
|
|
|
resolved:
|
|
|
|
description:
|
|
|
|
- whether the hostname's ipv4 address is already resolved or not
|
2022-09-06 21:07:46 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
|
|
|
resolved6:
|
|
|
|
description:
|
|
|
|
- whether the hostname's ipv6 address is already resolved or not
|
2022-09-06 21:07:46 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
|
|
|
timeout:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: int
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- the timeout for the utm to resolve the ip address for the hostname again
|
|
|
|
default: 0
|
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.utm
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Create UTM dns host entry
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_dns_host:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestDNSEntry
|
|
|
|
hostname: testentry.some.tld
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Remove UTM dns host entry
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_dns_host:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestDNSEntry
|
|
|
|
state: absent
|
|
|
|
"""
|
|
|
|
|
|
|
|
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
|
|
|
|
name:
|
|
|
|
description: The name of the object
|
|
|
|
type: str
|
|
|
|
address:
|
|
|
|
description: The ipv4 address of the object
|
|
|
|
type: str
|
|
|
|
address6:
|
|
|
|
description: The ipv6 address of the object
|
|
|
|
type: str
|
|
|
|
comment:
|
|
|
|
description: The comment string
|
|
|
|
type: str
|
|
|
|
hostname:
|
|
|
|
description: The hostname of the object
|
|
|
|
type: str
|
|
|
|
interface:
|
|
|
|
description: The reference name of the interface the object is associated with
|
|
|
|
type: str
|
|
|
|
resolved:
|
|
|
|
description: Whether the ipv4 address is resolved or not
|
|
|
|
type: bool
|
|
|
|
resolved6:
|
|
|
|
description: Whether the ipv6 address is resolved or not
|
|
|
|
type: bool
|
|
|
|
timeout:
|
|
|
|
description: The timeout until a new resolving will be attempted
|
|
|
|
type: int
|
|
|
|
"""
|
|
|
|
|
|
|
|
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 = "network/dns_host"
|
|
|
|
key_to_check_for_changes = ["comment", "hostname", "interface"]
|
|
|
|
module = UTMModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
name=dict(type='str', required=True),
|
|
|
|
address=dict(type='str', required=False, default='0.0.0.0'),
|
|
|
|
address6=dict(type='str', required=False, default='::'),
|
|
|
|
comment=dict(type='str', required=False, default=""),
|
|
|
|
hostname=dict(type='str', required=False),
|
|
|
|
interface=dict(type='str', required=False, default=""),
|
|
|
|
resolved=dict(type='bool', required=False, default=False),
|
|
|
|
resolved6=dict(type='bool', required=False, default=False),
|
|
|
|
timeout=dict(type='int', required=False, default=0),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
UTM(module, endpoint, key_to_check_for_changes).execute()
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg=to_native(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|