| 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_addrgrp |
| 15 |
short_description: Configure IPv4 address groups. |
| 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_addrgrp: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
allow_routing: |
| 34 |
aliases: ['allow-routing'] |
| 35 |
type: str |
| 36 |
description: Enable/disable use of this group in the static route configuration. |
| 37 |
choices: ['disable', 'enable'] |
| 38 |
color: |
| 39 |
type: int |
| 40 |
description: Color of icon on the GUI. |
| 41 |
comment: |
| 42 |
type: raw |
| 43 |
description: (dict or str) Comment. |
| 44 |
dynamic_mapping: |
| 45 |
type: list |
| 46 |
elements: dict |
| 47 |
description: Dynamic mapping. |
| 48 |
suboptions: |
| 49 |
_scope: |
| 50 |
type: list |
| 51 |
elements: dict |
| 52 |
description: Scope. |
| 53 |
suboptions: |
| 54 |
name: |
| 55 |
type: str |
| 56 |
description: Name. |
| 57 |
vdom: |
| 58 |
type: str |
| 59 |
description: Vdom. |
| 60 |
allow_routing: |
| 61 |
aliases: ['allow-routing'] |
| 62 |
type: str |
| 63 |
description: Allow routing. |
| 64 |
choices: ['disable', 'enable'] |
| 65 |
color: |
| 66 |
type: int |
| 67 |
description: Color. |
| 68 |
comment: |
| 69 |
type: raw |
| 70 |
description: (dict or str) Comment. |
| 71 |
exclude: |
| 72 |
type: str |
| 73 |
description: Exclude. |
| 74 |
choices: ['disable', 'enable'] |
| 75 |
exclude_member: |
| 76 |
aliases: ['exclude-member'] |
| 77 |
type: raw |
| 78 |
description: (list or str) Exclude member. |
| 79 |
member: |
| 80 |
type: list |
| 81 |
elements: str |
| 82 |
description: Member. |
| 83 |
tags: |
| 84 |
type: raw |
| 85 |
description: (list or str) Tags. |
| 86 |
uuid: |
| 87 |
type: str |
| 88 |
description: Uuid. |
| 89 |
visibility: |
| 90 |
type: str |
| 91 |
description: Visibility. |
| 92 |
choices: ['disable', 'enable'] |
| 93 |
_image_base64: |
| 94 |
aliases: ['_image-base64'] |
| 95 |
type: str |
| 96 |
description: Image base64. |
| 97 |
global_object: |
| 98 |
aliases: ['global-object'] |
| 99 |
type: int |
| 100 |
description: Global object. |
| 101 |
type: |
| 102 |
type: str |
| 103 |
description: Type. |
| 104 |
choices: ['default', 'array', 'folder'] |
| 105 |
fabric_object: |
| 106 |
aliases: ['fabric-object'] |
| 107 |
type: str |
| 108 |
description: Security Fabric global object setting. |
| 109 |
choices: ['disable', 'enable'] |
| 110 |
category: |
| 111 |
type: str |
| 112 |
description: Address group category. |
| 113 |
choices: ['default', 'ztna-ems-tag', 'ztna-geo-tag', 'telemetry'] |
| 114 |
member: |
| 115 |
type: list |
| 116 |
elements: str |
| 117 |
description: Address objects contained within the group. |
| 118 |
name: |
| 119 |
type: str |
| 120 |
description: Address group name. |
| 121 |
required: true |
| 122 |
tagging: |
| 123 |
type: list |
| 124 |
elements: dict |
| 125 |
description: Tagging. |
| 126 |
suboptions: |
| 127 |
category: |
| 128 |
type: str |
| 129 |
description: Tag category. |
| 130 |
name: |
| 131 |
type: str |
| 132 |
description: Tagging entry name. |
| 133 |
tags: |
| 134 |
type: raw |
| 135 |
description: (list) Tags. |
| 136 |
uuid: |
| 137 |
type: str |
| 138 |
description: Universally Unique Identifier |
| 139 |
visibility: |
| 140 |
type: str |
| 141 |
description: Enable/disable address visibility in the GUI. |
| 142 |
choices: ['disable', 'enable'] |
| 143 |
exclude: |
| 144 |
type: str |
| 145 |
description: Enable/disable address exclusion. |
| 146 |
choices: ['disable', 'enable'] |
| 147 |
exclude_member: |
| 148 |
aliases: ['exclude-member'] |
| 149 |
type: raw |
| 150 |
description: (list or str) Address exclusion member. |
| 151 |
tags: |
| 152 |
type: str |
| 153 |
description: Name |
| 154 |
_image_base64: |
| 155 |
aliases: ['_image-base64'] |
| 156 |
type: str |
| 157 |
description: Image base64. |
| 158 |
global_object: |
| 159 |
aliases: ['global-object'] |
| 160 |
type: int |
| 161 |
description: Global Object. |
| 162 |
type: |
| 163 |
type: str |
| 164 |
description: Address group type. |
| 165 |
choices: ['default', 'array', 'folder'] |
| 166 |
fabric_object: |
| 167 |
aliases: ['fabric-object'] |
| 168 |
type: str |
| 169 |
description: Security Fabric global object setting. |
| 170 |
choices: ['disable', 'enable'] |
| 171 |
category: |
| 172 |
type: str |
| 173 |
description: Address group category. |
| 174 |
choices: ['default', 'ztna-ems-tag', 'ztna-geo-tag', 'telemetry'] |
| 175 |
''' |
| 176 |
|
| 177 |
EXAMPLES = ''' |
| 178 |
- name: Example playbook |
| 179 |
hosts: fortimanagers |
| 180 |
gather_facts: false |
| 181 |
connection: httpapi |
| 182 |
vars: |
| 183 |
ansible_httpapi_use_ssl: true |
| 184 |
ansible_httpapi_validate_certs: false |
| 185 |
ansible_httpapi_port: 443 |
| 186 |
tasks: |
| 187 |
- name: Configure IPv4 address groups. |
| 188 |
fortinet.fortimanager.fmgr_firewall_addrgrp: |
| 189 |
bypass_validation: false |
| 190 |
adom: ansible |
| 191 |
state: present |
| 192 |
firewall_addrgrp: |
| 193 |
allow_routing: disable |
| 194 |
color: 0 |
| 195 |
member: "ansible-test1" # IPv4 address name |
| 196 |
name: "ansible-addrgrp4" # could not the same with other group, adress name, including IPv6 group and address |
| 197 |
visibility: disable |
| 198 |
|
| 199 |
- name: Gathering fortimanager facts |
| 200 |
hosts: fortimanagers |
| 201 |
gather_facts: false |
| 202 |
connection: httpapi |
| 203 |
vars: |
| 204 |
ansible_httpapi_use_ssl: true |
| 205 |
ansible_httpapi_validate_certs: false |
| 206 |
ansible_httpapi_port: 443 |
| 207 |
tasks: |
| 208 |
- name: Retrieve all the IPv4 address groups |
| 209 |
fortinet.fortimanager.fmgr_fact: |
| 210 |
facts: |
| 211 |
selector: "firewall_addrgrp" |
| 212 |
params: |
| 213 |
adom: "ansible" |
| 214 |
addrgrp: "your_value" |
| 215 |
''' |
| 216 |
|
| 217 |
RETURN = ''' |
| 218 |
meta: |
| 219 |
description: The result of the request. |
| 220 |
type: dict |
| 221 |
returned: always |
| 222 |
contains: |
| 223 |
request_url: |
| 224 |
description: The full url requested. |
| 225 |
returned: always |
| 226 |
type: str |
| 227 |
sample: /sys/login/user |
| 228 |
response_code: |
| 229 |
description: The status of api request. |
| 230 |
returned: always |
| 231 |
type: int |
| 232 |
sample: 0 |
| 233 |
response_data: |
| 234 |
description: The api response. |
| 235 |
type: list |
| 236 |
returned: always |
| 237 |
response_message: |
| 238 |
description: The descriptive message of the api response. |
| 239 |
type: str |
| 240 |
returned: always |
| 241 |
sample: OK. |
| 242 |
system_information: |
| 243 |
description: The information of the target system. |
| 244 |
type: dict |
| 245 |
returned: always |
| 246 |
rc: |
| 247 |
description: The status the request. |
| 248 |
type: int |
| 249 |
returned: always |
| 250 |
sample: 0 |
| 251 |
version_check_warning: |
| 252 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 253 |
type: list |
| 254 |
returned: complex |
| 255 |
''' |
| 256 |
from ansible.module_utils.basic import AnsibleModule |
| 257 |
from ansible.module_utils.connection import Connection |
| 258 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 259 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 260 |
|
| 261 |
|
| 262 |
def main(): |
| 263 |
urls_list = [ |
| 264 |
'/pm/config/adom/{adom}/obj/firewall/addrgrp', |
| 265 |
'/pm/config/global/obj/firewall/addrgrp' |
| 266 |
] |
| 267 |
module_arg_spec = { |
| 268 |
'adom': {'required': True, 'type': 'str'}, |
| 269 |
'revision_note': {'type': 'str'}, |
| 270 |
'firewall_addrgrp': { |
| 271 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 272 |
'options': { |
| 273 |
'allow-routing': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 274 |
'color': {'type': 'int'}, |
| 275 |
'comment': {'type': 'raw'}, |
| 276 |
'dynamic_mapping': { |
| 277 |
'type': 'list', |
| 278 |
'options': { |
| 279 |
'_scope': {'type': 'list', 'options': {'name': {'type': 'str'}, 'vdom': {'type': 'str'}}, 'elements': 'dict'}, |
| 280 |
'allow-routing': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 281 |
'color': {'type': 'int'}, |
| 282 |
'comment': {'type': 'raw'}, |
| 283 |
'exclude': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 284 |
'exclude-member': {'type': 'raw'}, |
| 285 |
'member': {'type': 'list', 'elements': 'str'}, |
| 286 |
'tags': {'type': 'raw'}, |
| 287 |
'uuid': {'type': 'str'}, |
| 288 |
'visibility': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 289 |
'_image-base64': {'v_range': [['6.2.2', '']], 'type': 'str'}, |
| 290 |
'global-object': {'v_range': [['6.4.0', '']], 'type': 'int'}, |
| 291 |
'type': {'v_range': [['6.4.0', '']], 'choices': ['default', 'array', 'folder'], 'type': 'str'}, |
| 292 |
'fabric-object': {'v_range': [['6.4.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 293 |
'category': {'v_range': [['7.0.0', '']], 'choices': ['default', 'ztna-ems-tag', 'ztna-geo-tag', 'telemetry'], 'type': 'str'} |
| 294 |
}, |
| 295 |
'elements': 'dict' |
| 296 |
}, |
| 297 |
'member': {'type': 'list', 'elements': 'str'}, |
| 298 |
'name': {'required': True, 'type': 'str'}, |
| 299 |
'tagging': { |
| 300 |
'type': 'list', |
| 301 |
'options': {'category': {'type': 'str'}, 'name': {'type': 'str'}, 'tags': {'type': 'raw'}}, |
| 302 |
'elements': 'dict' |
| 303 |
}, |
| 304 |
'uuid': {'type': 'str'}, |
| 305 |
'visibility': {'v_range': [['6.0.0', '7.6.2']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 306 |
'exclude': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 307 |
'exclude-member': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 308 |
'tags': {'v_range': [['6.2.0', '6.4.15'], ['7.4.8', '7.4.10']], 'type': 'str'}, |
| 309 |
'_image-base64': {'v_range': [['6.2.2', '']], 'type': 'str'}, |
| 310 |
'global-object': {'v_range': [['6.4.0', '']], 'type': 'int'}, |
| 311 |
'type': {'v_range': [['6.4.0', '']], 'choices': ['default', 'array', 'folder'], 'type': 'str'}, |
| 312 |
'fabric-object': {'v_range': [['6.4.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 313 |
'category': {'v_range': [['7.0.0', '']], 'choices': ['default', 'ztna-ems-tag', 'ztna-geo-tag', 'telemetry'], 'type': 'str'} |
| 314 |
} |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
module_option_spec = get_module_arg_spec('full crud') |
| 319 |
module_arg_spec.update(module_option_spec) |
| 320 |
check_galaxy_version(module_arg_spec) |
| 321 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'firewall_addrgrp'), |
| 322 |
supports_check_mode=True) |
| 323 |
if not module._socket_path: |
| 324 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 325 |
connection = Connection(module._socket_path) |
| 326 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 327 |
'name', 'data', module, connection) |
| 328 |
fmgr.process_crud() |
| 329 |
module.exit_json(meta=module.params) |
| 330 |
|
| 331 |
|
| 332 |
if __name__ == '__main__': |
| 333 |
main() |