| 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_address_dynamicmapping |
| 15 |
short_description: Configure IPv4 addresses. |
| 16 |
version_added: "2.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 |
address: |
| 29 |
description: The parameter (address) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
firewall_address_dynamicmapping: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
_scope: |
| 38 |
type: list |
| 39 |
elements: dict |
| 40 |
description: Scope. |
| 41 |
suboptions: |
| 42 |
name: |
| 43 |
type: str |
| 44 |
description: Name. |
| 45 |
vdom: |
| 46 |
type: str |
| 47 |
description: Vdom. |
| 48 |
allow_routing: |
| 49 |
aliases: ['allow-routing'] |
| 50 |
type: str |
| 51 |
description: Allow routing. |
| 52 |
choices: ['disable', 'enable'] |
| 53 |
associated_interface: |
| 54 |
aliases: ['associated-interface'] |
| 55 |
type: str |
| 56 |
description: Associated interface. |
| 57 |
cache_ttl: |
| 58 |
aliases: ['cache-ttl'] |
| 59 |
type: int |
| 60 |
description: Cache ttl. |
| 61 |
color: |
| 62 |
type: int |
| 63 |
description: Color. |
| 64 |
comment: |
| 65 |
type: raw |
| 66 |
description: (dict or str) Comment. |
| 67 |
country: |
| 68 |
type: str |
| 69 |
description: Country. |
| 70 |
end_ip: |
| 71 |
aliases: ['end-ip'] |
| 72 |
type: str |
| 73 |
description: End ip. |
| 74 |
end_mac: |
| 75 |
aliases: ['end-mac'] |
| 76 |
type: str |
| 77 |
description: End mac. |
| 78 |
epg_name: |
| 79 |
aliases: ['epg-name'] |
| 80 |
type: str |
| 81 |
description: Epg name. |
| 82 |
filter: |
| 83 |
type: str |
| 84 |
description: Filter. |
| 85 |
fqdn: |
| 86 |
type: str |
| 87 |
description: Fqdn. |
| 88 |
interface: |
| 89 |
type: str |
| 90 |
description: Interface. |
| 91 |
obj_id: |
| 92 |
aliases: ['obj-id'] |
| 93 |
type: str |
| 94 |
description: Obj id. |
| 95 |
organization: |
| 96 |
type: str |
| 97 |
description: Organization. |
| 98 |
policy_group: |
| 99 |
aliases: ['policy-group'] |
| 100 |
type: str |
| 101 |
description: Policy group. |
| 102 |
sdn: |
| 103 |
type: str |
| 104 |
description: Sdn. |
| 105 |
choices: ['aci', 'aws', 'nsx', 'nuage', 'azure', 'gcp', 'oci', 'openstack'] |
| 106 |
sdn_addr_type: |
| 107 |
aliases: ['sdn-addr-type'] |
| 108 |
type: str |
| 109 |
description: Sdn addr type. |
| 110 |
choices: ['private', 'public', 'all'] |
| 111 |
sdn_tag: |
| 112 |
aliases: ['sdn-tag'] |
| 113 |
type: str |
| 114 |
description: Sdn tag. |
| 115 |
start_ip: |
| 116 |
aliases: ['start-ip'] |
| 117 |
type: str |
| 118 |
description: Start ip. |
| 119 |
start_mac: |
| 120 |
aliases: ['start-mac'] |
| 121 |
type: str |
| 122 |
description: Start mac. |
| 123 |
subnet: |
| 124 |
type: str |
| 125 |
description: Subnet. |
| 126 |
subnet_name: |
| 127 |
aliases: ['subnet-name'] |
| 128 |
type: str |
| 129 |
description: Subnet name. |
| 130 |
tags: |
| 131 |
type: raw |
| 132 |
description: (list or str) Tags. |
| 133 |
tenant: |
| 134 |
type: str |
| 135 |
description: Tenant. |
| 136 |
type: |
| 137 |
type: str |
| 138 |
description: Type. |
| 139 |
choices: ['ipmask', 'iprange', 'fqdn', 'wildcard', 'geography', 'url', |
| 140 |
'wildcard-fqdn', 'nsx', 'aws', 'dynamic', 'interface-subnet', 'mac', |
| 141 |
'fqdn-group', 'route-tag'] |
| 142 |
url: |
| 143 |
type: str |
| 144 |
description: Url. |
| 145 |
uuid: |
| 146 |
type: str |
| 147 |
description: Uuid. |
| 148 |
visibility: |
| 149 |
type: str |
| 150 |
description: Visibility. |
| 151 |
choices: ['disable', 'enable'] |
| 152 |
wildcard: |
| 153 |
type: str |
| 154 |
description: Wildcard. |
| 155 |
wildcard_fqdn: |
| 156 |
aliases: ['wildcard-fqdn'] |
| 157 |
type: str |
| 158 |
description: Wildcard fqdn. |
| 159 |
_image_base64: |
| 160 |
aliases: ['_image-base64'] |
| 161 |
type: str |
| 162 |
description: Image base64. |
| 163 |
clearpass_spt: |
| 164 |
aliases: ['clearpass-spt'] |
| 165 |
type: str |
| 166 |
description: Clearpass spt. |
| 167 |
choices: ['unknown', 'healthy', 'quarantine', 'checkup', 'transition', 'infected', |
| 168 |
'transient'] |
| 169 |
fsso_group: |
| 170 |
aliases: ['fsso-group'] |
| 171 |
type: raw |
| 172 |
description: (list or str) Fsso group. |
| 173 |
sub_type: |
| 174 |
aliases: ['sub-type'] |
| 175 |
type: str |
| 176 |
description: Sub type. |
| 177 |
choices: ['sdn', 'clearpass-spt', 'fsso', 'ems-tag', 'swc-tag', 'fortivoice-tag', |
| 178 |
'fortinac-tag', 'fortipolicy-tag', 'device-identification', 'rsso', |
| 179 |
'external-resource', 'obsolete', 'telemetry'] |
| 180 |
global_object: |
| 181 |
aliases: ['global-object'] |
| 182 |
type: int |
| 183 |
description: Global object. |
| 184 |
obj_tag: |
| 185 |
aliases: ['obj-tag'] |
| 186 |
type: str |
| 187 |
description: Obj tag. |
| 188 |
obj_type: |
| 189 |
aliases: ['obj-type'] |
| 190 |
type: str |
| 191 |
description: Obj type. |
| 192 |
choices: ['ip', 'mac'] |
| 193 |
fabric_object: |
| 194 |
aliases: ['fabric-object'] |
| 195 |
type: str |
| 196 |
description: Security Fabric global object setting. |
| 197 |
choices: ['disable', 'enable'] |
| 198 |
macaddr: |
| 199 |
type: raw |
| 200 |
description: (list) Multiple MAC address ranges. |
| 201 |
node_ip_only: |
| 202 |
aliases: ['node-ip-only'] |
| 203 |
type: str |
| 204 |
description: Enable/disable collection of node addresses only in Kubernetes. |
| 205 |
choices: ['disable', 'enable'] |
| 206 |
dirty: |
| 207 |
type: str |
| 208 |
description: To be deleted address. |
| 209 |
choices: ['dirty', 'clean'] |
| 210 |
pattern_end: |
| 211 |
aliases: ['pattern-end'] |
| 212 |
type: int |
| 213 |
description: Pattern end. |
| 214 |
pattern_start: |
| 215 |
aliases: ['pattern-start'] |
| 216 |
type: int |
| 217 |
description: Pattern start. |
| 218 |
tag_detection_level: |
| 219 |
aliases: ['tag-detection-level'] |
| 220 |
type: str |
| 221 |
description: Tag detection level of dynamic address object. |
| 222 |
tag_type: |
| 223 |
aliases: ['tag-type'] |
| 224 |
type: str |
| 225 |
description: Tag type of dynamic address object. |
| 226 |
hw_model: |
| 227 |
aliases: ['hw-model'] |
| 228 |
type: str |
| 229 |
description: Dynamic address matching hardware model. |
| 230 |
hw_vendor: |
| 231 |
aliases: ['hw-vendor'] |
| 232 |
type: str |
| 233 |
description: Dynamic address matching hardware vendor. |
| 234 |
os: |
| 235 |
type: str |
| 236 |
description: Dynamic address matching operating system. |
| 237 |
route_tag: |
| 238 |
aliases: ['route-tag'] |
| 239 |
type: int |
| 240 |
description: Route-tag address. |
| 241 |
sw_version: |
| 242 |
aliases: ['sw-version'] |
| 243 |
type: str |
| 244 |
description: Dynamic address matching software version. |
| 245 |
sso_attribute_value: |
| 246 |
aliases: ['sso-attribute-value'] |
| 247 |
type: raw |
| 248 |
description: (list) Name |
| 249 |
agent_id: |
| 250 |
aliases: ['agent-id'] |
| 251 |
type: raw |
| 252 |
description: (list) Telemetry agent id. |
| 253 |
tag_uuid: |
| 254 |
aliases: ['tag-uuid'] |
| 255 |
type: str |
| 256 |
description: Foreign UUID of dynamic address object. |
| 257 |
passive_fqdn_learning: |
| 258 |
aliases: ['passive-fqdn-learning'] |
| 259 |
type: str |
| 260 |
description: Enable/disable passive learning of FQDNs. |
| 261 |
choices: ['disable', 'enable'] |
| 262 |
''' |
| 263 |
|
| 264 |
EXAMPLES = ''' |
| 265 |
- name: Example playbook |
| 266 |
hosts: fortimanagers |
| 267 |
gather_facts: false |
| 268 |
connection: httpapi |
| 269 |
vars: |
| 270 |
ansible_httpapi_use_ssl: true |
| 271 |
ansible_httpapi_validate_certs: false |
| 272 |
ansible_httpapi_port: 443 |
| 273 |
tasks: |
| 274 |
- name: Configure dynamic mappings of IPv4 address |
| 275 |
fortinet.fortimanager.fmgr_firewall_address_dynamicmapping: |
| 276 |
bypass_validation: true |
| 277 |
adom: ansible |
| 278 |
address: "ansible-test1" # name |
| 279 |
state: present |
| 280 |
firewall_address_dynamicmapping: |
| 281 |
_scope: |
| 282 |
- name: FGT_AWS # need a valid device name |
| 283 |
vdom: root # need a valid vdom name under the device |
| 284 |
allow_routing: disable # <value in [disable, enable]> |
| 285 |
cache_ttl: 0 |
| 286 |
color: 1 |
| 287 |
comment: "ansible-comment" |
| 288 |
subnet: "222.222.222.101/32" |
| 289 |
subnet_name: "ansible-test" |
| 290 |
type: ipmask # <value in [ipmask, iprange, fqdn, ...]> |
| 291 |
visibility: enable |
| 292 |
|
| 293 |
- name: Gathering fortimanager facts |
| 294 |
hosts: fortimanagers |
| 295 |
gather_facts: false |
| 296 |
connection: httpapi |
| 297 |
vars: |
| 298 |
ansible_httpapi_use_ssl: true |
| 299 |
ansible_httpapi_validate_certs: false |
| 300 |
ansible_httpapi_port: 443 |
| 301 |
tasks: |
| 302 |
- name: Retrieve all the dynamic mappings of IPv4 address |
| 303 |
fortinet.fortimanager.fmgr_fact: |
| 304 |
facts: |
| 305 |
selector: "firewall_address_dynamicmapping" |
| 306 |
params: |
| 307 |
adom: "ansible" |
| 308 |
address: "ansible-test1" # name |
| 309 |
dynamic_mapping: "your_value" |
| 310 |
''' |
| 311 |
|
| 312 |
RETURN = ''' |
| 313 |
meta: |
| 314 |
description: The result of the request. |
| 315 |
type: dict |
| 316 |
returned: always |
| 317 |
contains: |
| 318 |
request_url: |
| 319 |
description: The full url requested. |
| 320 |
returned: always |
| 321 |
type: str |
| 322 |
sample: /sys/login/user |
| 323 |
response_code: |
| 324 |
description: The status of api request. |
| 325 |
returned: always |
| 326 |
type: int |
| 327 |
sample: 0 |
| 328 |
response_data: |
| 329 |
description: The api response. |
| 330 |
type: list |
| 331 |
returned: always |
| 332 |
response_message: |
| 333 |
description: The descriptive message of the api response. |
| 334 |
type: str |
| 335 |
returned: always |
| 336 |
sample: OK. |
| 337 |
system_information: |
| 338 |
description: The information of the target system. |
| 339 |
type: dict |
| 340 |
returned: always |
| 341 |
rc: |
| 342 |
description: The status the request. |
| 343 |
type: int |
| 344 |
returned: always |
| 345 |
sample: 0 |
| 346 |
version_check_warning: |
| 347 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 348 |
type: list |
| 349 |
returned: complex |
| 350 |
''' |
| 351 |
from ansible.module_utils.basic import AnsibleModule |
| 352 |
from ansible.module_utils.connection import Connection |
| 353 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 354 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 355 |
|
| 356 |
|
| 357 |
def main(): |
| 358 |
urls_list = [ |
| 359 |
'/pm/config/adom/{adom}/obj/firewall/address/{address}/dynamic_mapping', |
| 360 |
'/pm/config/global/obj/firewall/address/{address}/dynamic_mapping' |
| 361 |
] |
| 362 |
module_arg_spec = { |
| 363 |
'adom': {'required': True, 'type': 'str'}, |
| 364 |
'address': {'required': True, 'type': 'str'}, |
| 365 |
'revision_note': {'type': 'str'}, |
| 366 |
'firewall_address_dynamicmapping': { |
| 367 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 368 |
'options': { |
| 369 |
'_scope': {'type': 'list', 'options': {'name': {'type': 'str'}, 'vdom': {'type': 'str'}}, 'elements': 'dict'}, |
| 370 |
'allow-routing': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 371 |
'associated-interface': {'type': 'str'}, |
| 372 |
'cache-ttl': {'type': 'int'}, |
| 373 |
'color': {'type': 'int'}, |
| 374 |
'comment': {'type': 'raw'}, |
| 375 |
'country': {'type': 'str'}, |
| 376 |
'end-ip': {'type': 'str'}, |
| 377 |
'end-mac': {'type': 'str'}, |
| 378 |
'epg-name': {'type': 'str'}, |
| 379 |
'filter': {'type': 'str'}, |
| 380 |
'fqdn': {'type': 'str'}, |
| 381 |
'interface': {'type': 'str'}, |
| 382 |
'obj-id': {'type': 'str'}, |
| 383 |
'organization': {'type': 'str'}, |
| 384 |
'policy-group': {'type': 'str'}, |
| 385 |
'sdn': {'choices': ['aci', 'aws', 'nsx', 'nuage', 'azure', 'gcp', 'oci', 'openstack'], 'type': 'str'}, |
| 386 |
'sdn-addr-type': {'choices': ['private', 'public', 'all'], 'type': 'str'}, |
| 387 |
'sdn-tag': {'type': 'str'}, |
| 388 |
'start-ip': {'type': 'str'}, |
| 389 |
'start-mac': {'type': 'str'}, |
| 390 |
'subnet': {'type': 'str'}, |
| 391 |
'subnet-name': {'type': 'str'}, |
| 392 |
'tags': {'type': 'raw'}, |
| 393 |
'tenant': {'type': 'str'}, |
| 394 |
'type': { |
| 395 |
'choices': [ |
| 396 |
'ipmask', 'iprange', 'fqdn', 'wildcard', 'geography', 'url', 'wildcard-fqdn', 'nsx', 'aws', 'dynamic', 'interface-subnet', 'mac', |
| 397 |
'fqdn-group', 'route-tag' |
| 398 |
], |
| 399 |
'type': 'str' |
| 400 |
}, |
| 401 |
'url': {'type': 'str'}, |
| 402 |
'uuid': {'type': 'str'}, |
| 403 |
'visibility': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 404 |
'wildcard': {'type': 'str'}, |
| 405 |
'wildcard-fqdn': {'type': 'str'}, |
| 406 |
'_image-base64': {'v_range': [['6.2.2', '']], 'type': 'str'}, |
| 407 |
'clearpass-spt': { |
| 408 |
'v_range': [['6.2.2', '']], |
| 409 |
'choices': ['unknown', 'healthy', 'quarantine', 'checkup', 'transition', 'infected', 'transient'], |
| 410 |
'type': 'str' |
| 411 |
}, |
| 412 |
'fsso-group': {'v_range': [['6.2.2', '']], 'type': 'raw'}, |
| 413 |
'sub-type': { |
| 414 |
'v_range': [['6.2.2', '']], |
| 415 |
'choices': [ |
| 416 |
'sdn', 'clearpass-spt', 'fsso', 'ems-tag', 'swc-tag', 'fortivoice-tag', 'fortinac-tag', 'fortipolicy-tag', |
| 417 |
'device-identification', 'rsso', 'external-resource', 'obsolete', 'telemetry' |
| 418 |
], |
| 419 |
'type': 'str' |
| 420 |
}, |
| 421 |
'global-object': {'v_range': [['6.4.0', '']], 'type': 'int'}, |
| 422 |
'obj-tag': {'v_range': [['6.4.2', '']], 'type': 'str'}, |
| 423 |
'obj-type': {'v_range': [['6.4.2', '']], 'choices': ['ip', 'mac'], 'type': 'str'}, |
| 424 |
'fabric-object': {'v_range': [['6.4.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 425 |
'macaddr': {'v_range': [['7.0.0', '']], 'type': 'raw'}, |
| 426 |
'node-ip-only': {'v_range': [['7.0.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 427 |
'dirty': {'v_range': [['7.0.3', '']], 'choices': ['dirty', 'clean'], 'type': 'str'}, |
| 428 |
'pattern-end': {'v_range': [['7.0.3', '']], 'type': 'int'}, |
| 429 |
'pattern-start': {'v_range': [['7.0.3', '']], 'type': 'int'}, |
| 430 |
'tag-detection-level': {'v_range': [['7.0.3', '']], 'type': 'str'}, |
| 431 |
'tag-type': {'v_range': [['7.0.3', '']], 'type': 'str'}, |
| 432 |
'hw-model': {'v_range': [['7.4.0', '']], 'type': 'str'}, |
| 433 |
'hw-vendor': {'v_range': [['7.4.0', '']], 'type': 'str'}, |
| 434 |
'os': {'v_range': [['7.4.0', '']], 'type': 'str'}, |
| 435 |
'route-tag': {'v_range': [['7.4.0', '']], 'type': 'int'}, |
| 436 |
'sw-version': {'v_range': [['7.4.0', '']], 'type': 'str'}, |
| 437 |
'sso-attribute-value': {'v_range': [['7.6.2', '']], 'type': 'raw'}, |
| 438 |
'agent-id': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 439 |
'tag-uuid': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 440 |
'passive-fqdn-learning': {'v_range': [['7.6.5', '']], 'choices': ['disable', 'enable'], 'type': 'str'} |
| 441 |
} |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
module_option_spec = get_module_arg_spec('full crud') |
| 446 |
module_arg_spec.update(module_option_spec) |
| 447 |
check_galaxy_version(module_arg_spec) |
| 448 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'firewall_address_dynamicmapping'), |
| 449 |
supports_check_mode=True) |
| 450 |
if not module._socket_path: |
| 451 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 452 |
connection = Connection(module._socket_path) |
| 453 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 454 |
'complex:{{module}}["_scope"][0]["name"]+"/"+{{module}}["_scope"][0]["vdom"]', 'data', module, connection) |
| 455 |
fmgr.process_crud() |
| 456 |
module.exit_json(meta=module.params) |
| 457 |
|
| 458 |
|
| 459 |
if __name__ == '__main__': |
| 460 |
main() |