| 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_firewall_service_custom |
| 15 |
short_description: Configure custom services. |
| 16 |
version_added: "1.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 |
firewall_service_custom: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
app_category: |
| 34 |
aliases: ['app-category'] |
| 35 |
type: raw |
| 36 |
description: (list) Application category ID. |
| 37 |
app_service_type: |
| 38 |
aliases: ['app-service-type'] |
| 39 |
type: str |
| 40 |
description: Application service type. |
| 41 |
choices: ['disable', 'app-id', 'app-category'] |
| 42 |
application: |
| 43 |
type: raw |
| 44 |
description: (list) Application ID. |
| 45 |
category: |
| 46 |
type: str |
| 47 |
description: Service category. |
| 48 |
check_reset_range: |
| 49 |
aliases: ['check-reset-range'] |
| 50 |
type: str |
| 51 |
description: Configure the type of ICMP error message verification. |
| 52 |
choices: ['disable', 'default', 'strict'] |
| 53 |
color: |
| 54 |
type: int |
| 55 |
description: Color of icon on the GUI. |
| 56 |
comment: |
| 57 |
type: raw |
| 58 |
description: (dict or str) Comment. |
| 59 |
fqdn: |
| 60 |
type: str |
| 61 |
description: Fully qualified domain name. |
| 62 |
helper: |
| 63 |
type: str |
| 64 |
description: Helper name. |
| 65 |
choices: ['disable', 'auto', 'ftp', 'tftp', 'ras', 'h323', 'tns', 'mms', 'sip', |
| 66 |
'pptp', 'rtsp', 'dns-udp', 'dns-tcp', 'pmap', 'rsh', 'dcerpc', 'mgcp', |
| 67 |
'gtp-c', 'gtp-u', 'gtp-b', 'pfcp'] |
| 68 |
icmpcode: |
| 69 |
type: int |
| 70 |
description: ICMP code. |
| 71 |
icmptype: |
| 72 |
type: int |
| 73 |
description: ICMP type. |
| 74 |
iprange: |
| 75 |
type: str |
| 76 |
description: Start and end of the IP range associated with service. |
| 77 |
name: |
| 78 |
type: str |
| 79 |
description: Custom service name. |
| 80 |
required: true |
| 81 |
protocol: |
| 82 |
type: str |
| 83 |
description: Protocol type based on IANA numbers. |
| 84 |
choices: ['ICMP', 'IP', 'TCP/UDP/SCTP', 'ICMP6', 'HTTP', 'FTP', 'CONNECT', |
| 85 |
'SOCKS', 'ALL', 'SOCKS-TCP', 'SOCKS-UDP', 'TCP/UDP/UDP-Lite/SCTP'] |
| 86 |
protocol_number: |
| 87 |
aliases: ['protocol-number'] |
| 88 |
type: int |
| 89 |
description: IP protocol number. |
| 90 |
proxy: |
| 91 |
type: str |
| 92 |
description: Enable/disable web proxy service. |
| 93 |
choices: ['disable', 'enable'] |
| 94 |
sctp_portrange: |
| 95 |
aliases: ['sctp-portrange'] |
| 96 |
type: str |
| 97 |
description: Multiple SCTP port ranges. |
| 98 |
session_ttl: |
| 99 |
aliases: ['session-ttl'] |
| 100 |
type: raw |
| 101 |
description: (int or str) Session TTL |
| 102 |
tcp_halfclose_timer: |
| 103 |
aliases: ['tcp-halfclose-timer'] |
| 104 |
type: int |
| 105 |
description: Wait time to close a TCP session waiting for an unanswered FIN packet |
| 106 |
tcp_halfopen_timer: |
| 107 |
aliases: ['tcp-halfopen-timer'] |
| 108 |
type: int |
| 109 |
description: Wait time to close a TCP session waiting for an unanswered open session packet |
| 110 |
tcp_portrange: |
| 111 |
aliases: ['tcp-portrange'] |
| 112 |
type: str |
| 113 |
description: Multiple TCP port ranges. |
| 114 |
tcp_timewait_timer: |
| 115 |
aliases: ['tcp-timewait-timer'] |
| 116 |
type: int |
| 117 |
description: Set the length of the TCP TIME-WAIT state in seconds |
| 118 |
udp_idle_timer: |
| 119 |
aliases: ['udp-idle-timer'] |
| 120 |
type: int |
| 121 |
description: UDP half close timeout |
| 122 |
udp_portrange: |
| 123 |
aliases: ['udp-portrange'] |
| 124 |
type: str |
| 125 |
description: Multiple UDP port ranges. |
| 126 |
visibility: |
| 127 |
type: str |
| 128 |
description: Enable/disable the visibility of the service on the GUI. |
| 129 |
choices: ['disable', 'enable'] |
| 130 |
explicit_proxy: |
| 131 |
aliases: ['explicit-proxy'] |
| 132 |
type: str |
| 133 |
description: Enable/disable explicit web proxy service. |
| 134 |
choices: ['disable', 'enable'] |
| 135 |
global_object: |
| 136 |
aliases: ['global-object'] |
| 137 |
type: int |
| 138 |
description: Global Object. |
| 139 |
fabric_object: |
| 140 |
aliases: ['fabric-object'] |
| 141 |
type: str |
| 142 |
description: Security Fabric global object setting. |
| 143 |
choices: ['disable', 'enable'] |
| 144 |
tcp_rst_timer: |
| 145 |
aliases: ['tcp-rst-timer'] |
| 146 |
type: int |
| 147 |
description: Set the length of the TCP CLOSE state in seconds |
| 148 |
uuid: |
| 149 |
type: str |
| 150 |
description: Universally Unique Identifier |
| 151 |
udplite_portrange: |
| 152 |
aliases: ['udplite-portrange'] |
| 153 |
type: str |
| 154 |
description: Multiple UDP-Lite port ranges. |
| 155 |
''' |
| 156 |
|
| 157 |
EXAMPLES = ''' |
| 158 |
- name: Example playbook |
| 159 |
hosts: fortimanagers |
| 160 |
gather_facts: false |
| 161 |
connection: httpapi |
| 162 |
vars: |
| 163 |
ansible_httpapi_use_ssl: true |
| 164 |
ansible_httpapi_validate_certs: false |
| 165 |
ansible_httpapi_port: 443 |
| 166 |
tasks: |
| 167 |
- name: Configure custom services. |
| 168 |
fortinet.fortimanager.fmgr_firewall_service_custom: |
| 169 |
bypass_validation: false |
| 170 |
adom: ansible |
| 171 |
state: present |
| 172 |
firewall_service_custom: |
| 173 |
app_service_type: disable # <value in [disable, app-id, app-category]> |
| 174 |
color: 1 |
| 175 |
comment: "comment" |
| 176 |
helper: auto # <value in [disable, auto, ftp, ...]> |
| 177 |
name: "ansible-test" |
| 178 |
protocol: ALL # <value in [ICMP, IP, TCP/UDP/SCTP, ...]> |
| 179 |
proxy: enable # <value in [disable, enable]> |
| 180 |
visibility: enable # <value in [disable, enable]> |
| 181 |
|
| 182 |
- name: Gathering fortimanager facts |
| 183 |
hosts: fortimanagers |
| 184 |
gather_facts: false |
| 185 |
connection: httpapi |
| 186 |
vars: |
| 187 |
ansible_httpapi_use_ssl: true |
| 188 |
ansible_httpapi_validate_certs: false |
| 189 |
ansible_httpapi_port: 443 |
| 190 |
tasks: |
| 191 |
- name: Retrieve all the custom services |
| 192 |
fortinet.fortimanager.fmgr_fact: |
| 193 |
facts: |
| 194 |
selector: "firewall_service_custom" |
| 195 |
params: |
| 196 |
adom: "ansible" |
| 197 |
custom: "your_value" |
| 198 |
''' |
| 199 |
|
| 200 |
RETURN = ''' |
| 201 |
meta: |
| 202 |
description: The result of the request. |
| 203 |
type: dict |
| 204 |
returned: always |
| 205 |
contains: |
| 206 |
request_url: |
| 207 |
description: The full url requested. |
| 208 |
returned: always |
| 209 |
type: str |
| 210 |
sample: /sys/login/user |
| 211 |
response_code: |
| 212 |
description: The status of api request. |
| 213 |
returned: always |
| 214 |
type: int |
| 215 |
sample: 0 |
| 216 |
response_data: |
| 217 |
description: The api response. |
| 218 |
type: list |
| 219 |
returned: always |
| 220 |
response_message: |
| 221 |
description: The descriptive message of the api response. |
| 222 |
type: str |
| 223 |
returned: always |
| 224 |
sample: OK. |
| 225 |
system_information: |
| 226 |
description: The information of the target system. |
| 227 |
type: dict |
| 228 |
returned: always |
| 229 |
rc: |
| 230 |
description: The status the request. |
| 231 |
type: int |
| 232 |
returned: always |
| 233 |
sample: 0 |
| 234 |
version_check_warning: |
| 235 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 236 |
type: list |
| 237 |
returned: complex |
| 238 |
''' |
| 239 |
from ansible.module_utils.basic import AnsibleModule |
| 240 |
from ansible.module_utils.connection import Connection |
| 241 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 242 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 243 |
|
| 244 |
|
| 245 |
def main(): |
| 246 |
urls_list = [ |
| 247 |
'/pm/config/adom/{adom}/obj/firewall/service/custom', |
| 248 |
'/pm/config/global/obj/firewall/service/custom' |
| 249 |
] |
| 250 |
module_arg_spec = { |
| 251 |
'adom': {'required': True, 'type': 'str'}, |
| 252 |
'revision_note': {'type': 'str'}, |
| 253 |
'firewall_service_custom': { |
| 254 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 255 |
'options': { |
| 256 |
'app-category': {'type': 'raw'}, |
| 257 |
'app-service-type': {'choices': ['disable', 'app-id', 'app-category'], 'type': 'str'}, |
| 258 |
'application': {'type': 'raw'}, |
| 259 |
'category': {'type': 'str'}, |
| 260 |
'check-reset-range': {'choices': ['disable', 'default', 'strict'], 'type': 'str'}, |
| 261 |
'color': {'type': 'int'}, |
| 262 |
'comment': {'type': 'raw'}, |
| 263 |
'fqdn': {'type': 'str'}, |
| 264 |
'helper': { |
| 265 |
'choices': [ |
| 266 |
'disable', 'auto', 'ftp', 'tftp', 'ras', 'h323', 'tns', 'mms', 'sip', 'pptp', 'rtsp', 'dns-udp', 'dns-tcp', 'pmap', 'rsh', |
| 267 |
'dcerpc', 'mgcp', 'gtp-c', 'gtp-u', 'gtp-b', 'pfcp' |
| 268 |
], |
| 269 |
'type': 'str' |
| 270 |
}, |
| 271 |
'icmpcode': {'type': 'int'}, |
| 272 |
'icmptype': {'type': 'int'}, |
| 273 |
'iprange': {'type': 'str'}, |
| 274 |
'name': {'required': True, 'type': 'str'}, |
| 275 |
'protocol': { |
| 276 |
'choices': [ |
| 277 |
'ICMP', 'IP', 'TCP/UDP/SCTP', 'ICMP6', 'HTTP', 'FTP', 'CONNECT', 'SOCKS', 'ALL', 'SOCKS-TCP', 'SOCKS-UDP', |
| 278 |
'TCP/UDP/UDP-Lite/SCTP' |
| 279 |
], |
| 280 |
'type': 'str' |
| 281 |
}, |
| 282 |
'protocol-number': {'type': 'int'}, |
| 283 |
'proxy': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 284 |
'sctp-portrange': {'type': 'str'}, |
| 285 |
'session-ttl': {'type': 'raw'}, |
| 286 |
'tcp-halfclose-timer': {'type': 'int'}, |
| 287 |
'tcp-halfopen-timer': {'type': 'int'}, |
| 288 |
'tcp-portrange': {'type': 'str'}, |
| 289 |
'tcp-timewait-timer': {'type': 'int'}, |
| 290 |
'udp-idle-timer': {'type': 'int'}, |
| 291 |
'udp-portrange': {'type': 'str'}, |
| 292 |
'visibility': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 293 |
'explicit-proxy': {'v_range': [['6.2.0', '6.2.13']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 294 |
'global-object': {'v_range': [['6.4.0', '']], 'type': 'int'}, |
| 295 |
'fabric-object': {'v_range': [['6.4.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 296 |
'tcp-rst-timer': {'v_range': [['7.0.0', '']], 'type': 'int'}, |
| 297 |
'uuid': {'v_range': [['7.4.2', '']], 'type': 'str'}, |
| 298 |
'udplite-portrange': {'v_range': [['7.6.0', '']], 'type': 'str'} |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
module_option_spec = get_module_arg_spec('full crud') |
| 304 |
module_arg_spec.update(module_option_spec) |
| 305 |
check_galaxy_version(module_arg_spec) |
| 306 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'firewall_service_custom'), |
| 307 |
supports_check_mode=True) |
| 308 |
if not module._socket_path: |
| 309 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 310 |
connection = Connection(module._socket_path) |
| 311 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 312 |
'name', 'data', module, connection) |
| 313 |
fmgr.process_crud() |
| 314 |
module.exit_json(meta=module.params) |
| 315 |
|
| 316 |
|
| 317 |
if __name__ == '__main__': |
| 318 |
main() |