| 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_devprof_system_dns |
| 15 |
short_description: Configure DNS. |
| 16 |
version_added: "1.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.partial_crud |
| 20 |
options: |
| 21 |
adom: |
| 22 |
description: The parameter (adom) in requested url. |
| 23 |
type: str |
| 24 |
required: true |
| 25 |
devprof: |
| 26 |
description: The parameter (devprof) in requested url. |
| 27 |
type: str |
| 28 |
required: true |
| 29 |
devprof_system_dns: |
| 30 |
description: The top level parameters set. |
| 31 |
required: false |
| 32 |
type: dict |
| 33 |
suboptions: |
| 34 |
cache_notfound_responses: |
| 35 |
aliases: ['cache-notfound-responses'] |
| 36 |
type: str |
| 37 |
description: Enable/disable response from the DNS server when a record is not in cache. |
| 38 |
choices: ['disable', 'enable'] |
| 39 |
dns_cache_limit: |
| 40 |
aliases: ['dns-cache-limit'] |
| 41 |
type: int |
| 42 |
description: Maximum number of records in the DNS cache. |
| 43 |
dns_cache_ttl: |
| 44 |
aliases: ['dns-cache-ttl'] |
| 45 |
type: int |
| 46 |
description: Duration in seconds that the DNS cache retains information. |
| 47 |
domain: |
| 48 |
type: raw |
| 49 |
description: (list or str) Domain name suffix for the IP addresses of the DNS server. |
| 50 |
ip6_primary: |
| 51 |
aliases: ['ip6-primary'] |
| 52 |
type: str |
| 53 |
description: Primary DNS server IPv6 address. |
| 54 |
ip6_secondary: |
| 55 |
aliases: ['ip6-secondary'] |
| 56 |
type: str |
| 57 |
description: Secondary DNS server IPv6 address. |
| 58 |
primary: |
| 59 |
type: str |
| 60 |
description: Primary DNS server IP address. |
| 61 |
secondary: |
| 62 |
type: str |
| 63 |
description: Secondary DNS server IP address. |
| 64 |
dns_over_tls: |
| 65 |
aliases: ['dns-over-tls'] |
| 66 |
type: str |
| 67 |
description: Enable/disable/enforce DNS over TLS. |
| 68 |
choices: ['disable', 'enable', 'enforce'] |
| 69 |
retry: |
| 70 |
type: int |
| 71 |
description: Number of times to retry |
| 72 |
server_hostname: |
| 73 |
aliases: ['server-hostname'] |
| 74 |
type: raw |
| 75 |
description: (list) DNS server host name list. |
| 76 |
ssl_certificate: |
| 77 |
aliases: ['ssl-certificate'] |
| 78 |
type: str |
| 79 |
description: Name of local certificate for SSL connections. |
| 80 |
timeout: |
| 81 |
type: int |
| 82 |
description: DNS query timeout interval in seconds |
| 83 |
interface: |
| 84 |
type: str |
| 85 |
description: Specify outgoing interface to reach server. |
| 86 |
interface_select_method: |
| 87 |
aliases: ['interface-select-method'] |
| 88 |
type: str |
| 89 |
description: Specify how to select outgoing interface to reach server. |
| 90 |
choices: ['auto', 'sdwan', 'specify'] |
| 91 |
alt_primary: |
| 92 |
aliases: ['alt-primary'] |
| 93 |
type: str |
| 94 |
description: Alternate primary DNS server. |
| 95 |
alt_secondary: |
| 96 |
aliases: ['alt-secondary'] |
| 97 |
type: str |
| 98 |
description: Alternate secondary DNS server. |
| 99 |
fqdn_cache_ttl: |
| 100 |
aliases: ['fqdn-cache-ttl'] |
| 101 |
type: int |
| 102 |
description: FQDN cache time to live in seconds |
| 103 |
fqdn_max_refresh: |
| 104 |
aliases: ['fqdn-max-refresh'] |
| 105 |
type: int |
| 106 |
description: FQDN cache maximum refresh time in seconds |
| 107 |
fqdn_min_refresh: |
| 108 |
aliases: ['fqdn-min-refresh'] |
| 109 |
type: int |
| 110 |
description: FQDN cache minimum refresh time in seconds |
| 111 |
log: |
| 112 |
type: str |
| 113 |
description: Local DNS log setting. |
| 114 |
choices: ['disable', 'error', 'all'] |
| 115 |
protocol: |
| 116 |
type: list |
| 117 |
elements: str |
| 118 |
description: DNS transport protocols. |
| 119 |
choices: ['cleartext', 'dot', 'doh'] |
| 120 |
server_select_method: |
| 121 |
aliases: ['server-select-method'] |
| 122 |
type: str |
| 123 |
description: Specify how configured servers are prioritized. |
| 124 |
choices: ['least-rtt', 'failover'] |
| 125 |
source_ip: |
| 126 |
aliases: ['source-ip'] |
| 127 |
type: str |
| 128 |
description: IP address used by the DNS server as its source IP. |
| 129 |
vrf_select: |
| 130 |
aliases: ['vrf-select'] |
| 131 |
type: int |
| 132 |
description: VRF ID used for connection to server. |
| 133 |
source_ip_interface: |
| 134 |
aliases: ['source-ip-interface'] |
| 135 |
type: raw |
| 136 |
description: (list) IP address of the specified interface as the source IP address. |
| 137 |
hostname_ttl: |
| 138 |
aliases: ['hostname-ttl'] |
| 139 |
type: int |
| 140 |
description: TTL of hostname table entries |
| 141 |
hostname_limit: |
| 142 |
aliases: ['hostname-limit'] |
| 143 |
type: int |
| 144 |
description: Limit of the number of hostname table entries |
| 145 |
root_servers: |
| 146 |
aliases: ['root-servers'] |
| 147 |
type: str |
| 148 |
description: Configure up to two preferred servers that serve the DNS root zone |
| 149 |
''' |
| 150 |
|
| 151 |
EXAMPLES = ''' |
| 152 |
- name: Example playbook (generated based on argument schema) |
| 153 |
hosts: fortimanagers |
| 154 |
connection: httpapi |
| 155 |
gather_facts: false |
| 156 |
tasks: |
| 157 |
- name: Configure DNS. |
| 158 |
fortinet.fortimanager.fmgr_devprof_system_dns: |
| 159 |
# workspace_locking_adom: <global or your adom name> |
| 160 |
adom: <your own value> |
| 161 |
devprof: <your own value> |
| 162 |
devprof_system_dns: |
| 163 |
# cache_notfound_responses: <value in [disable, enable]> |
| 164 |
# dns_cache_limit: <integer> |
| 165 |
# dns_cache_ttl: <integer> |
| 166 |
# domain: <list or string> |
| 167 |
# ip6_primary: <string> |
| 168 |
# ip6_secondary: <string> |
| 169 |
# primary: <string> |
| 170 |
# secondary: <string> |
| 171 |
# dns_over_tls: <value in [disable, enable, enforce]> |
| 172 |
# retry: <integer> |
| 173 |
# server_hostname: <list or string> |
| 174 |
# ssl_certificate: <string> |
| 175 |
# timeout: <integer> |
| 176 |
# interface: <string> |
| 177 |
# interface_select_method: <value in [auto, sdwan, specify]> |
| 178 |
# alt_primary: <string> |
| 179 |
# alt_secondary: <string> |
| 180 |
# fqdn_cache_ttl: <integer> |
| 181 |
# fqdn_max_refresh: <integer> |
| 182 |
# fqdn_min_refresh: <integer> |
| 183 |
# log: <value in [disable, error, all]> |
| 184 |
# protocol: ["cleartext", "dot", "doh"] |
| 185 |
# server_select_method: <value in [least-rtt, failover]> |
| 186 |
# source_ip: <string> |
| 187 |
# vrf_select: <integer> |
| 188 |
# source_ip_interface: <list or string> |
| 189 |
# hostname_ttl: <integer> |
| 190 |
# hostname_limit: <integer> |
| 191 |
# root_servers: <string> |
| 192 |
''' |
| 193 |
|
| 194 |
RETURN = ''' |
| 195 |
meta: |
| 196 |
description: The result of the request. |
| 197 |
type: dict |
| 198 |
returned: always |
| 199 |
contains: |
| 200 |
request_url: |
| 201 |
description: The full url requested. |
| 202 |
returned: always |
| 203 |
type: str |
| 204 |
sample: /sys/login/user |
| 205 |
response_code: |
| 206 |
description: The status of api request. |
| 207 |
returned: always |
| 208 |
type: int |
| 209 |
sample: 0 |
| 210 |
response_data: |
| 211 |
description: The api response. |
| 212 |
type: list |
| 213 |
returned: always |
| 214 |
response_message: |
| 215 |
description: The descriptive message of the api response. |
| 216 |
type: str |
| 217 |
returned: always |
| 218 |
sample: OK. |
| 219 |
system_information: |
| 220 |
description: The information of the target system. |
| 221 |
type: dict |
| 222 |
returned: always |
| 223 |
rc: |
| 224 |
description: The status the request. |
| 225 |
type: int |
| 226 |
returned: always |
| 227 |
sample: 0 |
| 228 |
version_check_warning: |
| 229 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 230 |
type: list |
| 231 |
returned: complex |
| 232 |
''' |
| 233 |
from ansible.module_utils.basic import AnsibleModule |
| 234 |
from ansible.module_utils.connection import Connection |
| 235 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 236 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 237 |
|
| 238 |
|
| 239 |
def main(): |
| 240 |
urls_list = [ |
| 241 |
'/pm/config/adom/{adom}/devprof/{devprof}/system/dns' |
| 242 |
] |
| 243 |
module_arg_spec = { |
| 244 |
'adom': {'required': True, 'type': 'str'}, |
| 245 |
'devprof': {'required': True, 'type': 'str'}, |
| 246 |
'devprof_system_dns': { |
| 247 |
'type': 'dict', 'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], |
| 248 |
'options': { |
| 249 |
'cache-notfound-responses': { |
| 250 |
'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], |
| 251 |
'choices': ['disable', 'enable'], |
| 252 |
'type': 'str' |
| 253 |
}, |
| 254 |
'dns-cache-limit': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'int'}, |
| 255 |
'dns-cache-ttl': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'int'}, |
| 256 |
'domain': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'raw'}, |
| 257 |
'ip6-primary': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'str'}, |
| 258 |
'ip6-secondary': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'str'}, |
| 259 |
'primary': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'str'}, |
| 260 |
'secondary': {'v_range': [['6.0.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'str'}, |
| 261 |
'dns-over-tls': { |
| 262 |
'v_range': [['6.2.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], |
| 263 |
'choices': ['disable', 'enable', 'enforce'], |
| 264 |
'type': 'str' |
| 265 |
}, |
| 266 |
'retry': {'v_range': [['6.2.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'int'}, |
| 267 |
'server-hostname': {'v_range': [['6.2.1', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'raw'}, |
| 268 |
'ssl-certificate': {'v_range': [['6.2.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'str'}, |
| 269 |
'timeout': {'v_range': [['6.2.0', '6.2.5'], ['6.2.7', '6.4.1'], ['7.6.5', '']], 'type': 'int'}, |
| 270 |
'interface': {'v_range': [['6.2.5', '6.2.5'], ['6.2.7', '6.2.13'], ['6.4.1', '6.4.1'], ['7.6.5', '']], 'type': 'str'}, |
| 271 |
'interface-select-method': { |
| 272 |
'v_range': [['6.2.5', '6.2.5'], ['6.2.7', '6.2.13'], ['6.4.1', '6.4.1'], ['7.6.5', '']], |
| 273 |
'choices': ['auto', 'sdwan', 'specify'], |
| 274 |
'type': 'str' |
| 275 |
}, |
| 276 |
'alt-primary': {'v_range': [['7.6.5', '']], 'type': 'str'}, |
| 277 |
'alt-secondary': {'v_range': [['7.6.5', '']], 'type': 'str'}, |
| 278 |
'fqdn-cache-ttl': {'v_range': [['7.6.5', '']], 'type': 'int'}, |
| 279 |
'fqdn-max-refresh': {'v_range': [['7.6.5', '']], 'type': 'int'}, |
| 280 |
'fqdn-min-refresh': {'v_range': [['7.6.5', '']], 'type': 'int'}, |
| 281 |
'log': {'v_range': [['7.6.5', '']], 'choices': ['disable', 'error', 'all'], 'type': 'str'}, |
| 282 |
'protocol': {'v_range': [['7.6.5', '']], 'type': 'list', 'choices': ['cleartext', 'dot', 'doh'], 'elements': 'str'}, |
| 283 |
'server-select-method': {'v_range': [['7.6.5', '']], 'choices': ['least-rtt', 'failover'], 'type': 'str'}, |
| 284 |
'source-ip': {'v_range': [['7.6.5', '']], 'type': 'str'}, |
| 285 |
'vrf-select': {'v_range': [['7.6.5', '']], 'type': 'int'}, |
| 286 |
'source-ip-interface': {'v_range': [['7.6.5', '']], 'type': 'raw'}, |
| 287 |
'hostname-ttl': {'v_range': [['7.6.5', '']], 'type': 'int'}, |
| 288 |
'hostname-limit': {'v_range': [['7.6.5', '']], 'type': 'int'}, |
| 289 |
'root-servers': {'v_range': [['7.6.5', '']], 'type': 'str'} |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
module_option_spec = get_module_arg_spec('partial crud') |
| 295 |
module_arg_spec.update(module_option_spec) |
| 296 |
check_galaxy_version(module_arg_spec) |
| 297 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'devprof_system_dns'), |
| 298 |
supports_check_mode=True) |
| 299 |
if not module._socket_path: |
| 300 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 301 |
connection = Connection(module._socket_path) |
| 302 |
fmgr = NAPIManager('partial crud', module_arg_spec, urls_list, |
| 303 |
None, 'data', module, connection) |
| 304 |
fmgr.process_partial_crud() |
| 305 |
module.exit_json(meta=module.params) |
| 306 |
|
| 307 |
|
| 308 |
if __name__ == '__main__': |
| 309 |
main() |