| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage Check Point Firewall (c) 2019 |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
from __future__ import absolute_import, division, print_function |
| 21 |
|
| 22 |
__metaclass__ = type |
| 23 |
|
| 24 |
ANSIBLE_METADATA = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["deprecated"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_host |
| 33 |
short_description: Manages host objects on Check Point over Web Services API |
| 34 |
description: |
| 35 |
- Manages host objects on Check Point devices including creating, updating and removing objects. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- Available from R80 management version. |
| 38 |
version_added: "1.0.0" |
| 39 |
author: "Or Soffer (@chkp-orso)" |
| 40 |
options: |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Object name. |
| 44 |
type: str |
| 45 |
required: True |
| 46 |
ip_address: |
| 47 |
description: |
| 48 |
- IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly. |
| 49 |
type: str |
| 50 |
ipv4_address: |
| 51 |
description: |
| 52 |
- IPv4 address. |
| 53 |
type: str |
| 54 |
ipv6_address: |
| 55 |
description: |
| 56 |
- IPv6 address. |
| 57 |
type: str |
| 58 |
interfaces: |
| 59 |
description: |
| 60 |
- Host interfaces. |
| 61 |
- Available from R80.10 management version. |
| 62 |
type: list |
| 63 |
elements: dict |
| 64 |
suboptions: |
| 65 |
name: |
| 66 |
description: |
| 67 |
- Interface name. |
| 68 |
type: str |
| 69 |
subnet: |
| 70 |
description: |
| 71 |
- IPv4 or IPv6 network address. If both addresses are required use subnet4 and subnet6 fields explicitly. |
| 72 |
type: str |
| 73 |
subnet4: |
| 74 |
description: |
| 75 |
- IPv4 network address. |
| 76 |
type: str |
| 77 |
subnet6: |
| 78 |
description: |
| 79 |
- IPv6 network address. |
| 80 |
type: str |
| 81 |
mask_length: |
| 82 |
description: |
| 83 |
- IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and mask-length6 fields explicitly. Instead of IPv4 mask |
| 84 |
length it is possible to specify IPv4 mask itself in subnet-mask field. |
| 85 |
type: int |
| 86 |
mask_length4: |
| 87 |
description: |
| 88 |
- IPv4 network mask length. |
| 89 |
type: int |
| 90 |
mask_length6: |
| 91 |
description: |
| 92 |
- IPv6 network mask length. |
| 93 |
type: int |
| 94 |
subnet_mask: |
| 95 |
description: |
| 96 |
- IPv4 network mask. |
| 97 |
type: str |
| 98 |
color: |
| 99 |
description: |
| 100 |
- Color of the object. Should be one of existing colors. |
| 101 |
type: str |
| 102 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', |
| 103 |
'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', |
| 104 |
'light green', 'lemon chiffon', 'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', |
| 105 |
'orange', 'red', 'sienna', 'yellow'] |
| 106 |
comments: |
| 107 |
description: |
| 108 |
- Comments string. |
| 109 |
type: str |
| 110 |
details_level: |
| 111 |
description: |
| 112 |
- The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed |
| 113 |
representation of the object. |
| 114 |
type: str |
| 115 |
choices: ['uid', 'standard', 'full'] |
| 116 |
ignore_warnings: |
| 117 |
description: |
| 118 |
- Apply changes ignoring warnings. |
| 119 |
type: bool |
| 120 |
ignore_errors: |
| 121 |
description: |
| 122 |
- Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored. |
| 123 |
type: bool |
| 124 |
nat_settings: |
| 125 |
description: |
| 126 |
- NAT settings. |
| 127 |
type: dict |
| 128 |
suboptions: |
| 129 |
auto_rule: |
| 130 |
description: |
| 131 |
- Whether to add automatic address translation rules. |
| 132 |
type: bool |
| 133 |
ip_address: |
| 134 |
description: |
| 135 |
- IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly. This parameter is not |
| 136 |
required in case "method" parameter is "hide" and "hide-behind" parameter is "gateway". |
| 137 |
type: str |
| 138 |
ipv4_address: |
| 139 |
description: |
| 140 |
- IPv4 address. |
| 141 |
type: str |
| 142 |
ipv6_address: |
| 143 |
description: |
| 144 |
- IPv6 address. |
| 145 |
type: str |
| 146 |
hide_behind: |
| 147 |
description: |
| 148 |
- Hide behind method. This parameter is not required in case "method" parameter is "static". |
| 149 |
type: str |
| 150 |
choices: ['gateway', 'ip-address'] |
| 151 |
install_on: |
| 152 |
description: |
| 153 |
- Which gateway should apply the NAT translation. |
| 154 |
type: str |
| 155 |
method: |
| 156 |
description: |
| 157 |
- NAT translation method. |
| 158 |
type: str |
| 159 |
choices: ['hide', 'static'] |
| 160 |
tags: |
| 161 |
description: |
| 162 |
- Collection of tag identifiers. |
| 163 |
type: list |
| 164 |
elements: str |
| 165 |
host_servers: |
| 166 |
description: |
| 167 |
- Servers Configuration. |
| 168 |
type: dict |
| 169 |
suboptions: |
| 170 |
dns_server: |
| 171 |
description: |
| 172 |
- Gets True if this server is a DNS Server. |
| 173 |
type: bool |
| 174 |
mail_server: |
| 175 |
description: |
| 176 |
- Gets True if this server is a Mail Server. |
| 177 |
type: bool |
| 178 |
web_server: |
| 179 |
description: |
| 180 |
- Gets True if this server is a Web Server. |
| 181 |
type: bool |
| 182 |
web_server_config: |
| 183 |
description: |
| 184 |
- Web Server configuration. |
| 185 |
type: dict |
| 186 |
suboptions: |
| 187 |
additional_ports: |
| 188 |
description: |
| 189 |
- Server additional ports. |
| 190 |
type: list |
| 191 |
elements: str |
| 192 |
application_engines: |
| 193 |
description: |
| 194 |
- Application engines of this web server. |
| 195 |
type: list |
| 196 |
elements: str |
| 197 |
listen_standard_port: |
| 198 |
description: |
| 199 |
- Whether server listens to standard port. |
| 200 |
type: bool |
| 201 |
operating_system: |
| 202 |
description: |
| 203 |
- Operating System. |
| 204 |
type: str |
| 205 |
choices: ['sparc linux', 'windows', 'other', 'x86 linux', 'sparc solaris'] |
| 206 |
protected_by: |
| 207 |
description: |
| 208 |
- Network object which protects this server identified by the name or UID. |
| 209 |
type: str |
| 210 |
color: |
| 211 |
description: |
| 212 |
- Color of the object. Should be one of existing colors. |
| 213 |
type: str |
| 214 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 215 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 216 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 217 |
comments: |
| 218 |
description: |
| 219 |
- Comments string. |
| 220 |
type: str |
| 221 |
details_level: |
| 222 |
description: |
| 223 |
- The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed |
| 224 |
representation of the object. |
| 225 |
type: str |
| 226 |
choices: ['uid', 'standard', 'full'] |
| 227 |
groups: |
| 228 |
description: |
| 229 |
- Collection of group identifiers. |
| 230 |
type: list |
| 231 |
elements: str |
| 232 |
ignore_warnings: |
| 233 |
description: |
| 234 |
- Apply changes ignoring warnings. |
| 235 |
type: bool |
| 236 |
ignore_errors: |
| 237 |
description: |
| 238 |
- Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored. |
| 239 |
type: bool |
| 240 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 241 |
""" |
| 242 |
|
| 243 |
EXAMPLES = """ |
| 244 |
- name: add-host |
| 245 |
cp_mgmt_host: |
| 246 |
ip_address: 192.0.2.1 |
| 247 |
name: New Host 1 |
| 248 |
state: present |
| 249 |
|
| 250 |
- name: set-host |
| 251 |
cp_mgmt_host: |
| 252 |
color: green |
| 253 |
ipv4_address: 192.0.2.2 |
| 254 |
name: New Host 1 |
| 255 |
state: present |
| 256 |
|
| 257 |
- name: delete-host |
| 258 |
cp_mgmt_host: |
| 259 |
name: New Host 1 |
| 260 |
state: absent |
| 261 |
""" |
| 262 |
|
| 263 |
RETURN = """ |
| 264 |
cp_mgmt_host: |
| 265 |
description: The checkpoint object created or updated. |
| 266 |
returned: always, except when deleting the object. |
| 267 |
type: dict |
| 268 |
""" |
| 269 |
|
| 270 |
from ansible.module_utils.basic import AnsibleModule |
| 271 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 272 |
checkpoint_argument_spec_for_objects, |
| 273 |
api_call, |
| 274 |
) |
| 275 |
|
| 276 |
|
| 277 |
def main(): |
| 278 |
argument_spec = dict( |
| 279 |
name=dict(type="str", required=True), |
| 280 |
ip_address=dict(type="str"), |
| 281 |
ipv4_address=dict(type="str"), |
| 282 |
ipv6_address=dict(type="str"), |
| 283 |
interfaces=dict( |
| 284 |
type="list", |
| 285 |
elements="dict", |
| 286 |
options=dict( |
| 287 |
name=dict(type="str"), |
| 288 |
subnet=dict(type="str"), |
| 289 |
subnet4=dict(type="str"), |
| 290 |
subnet6=dict(type="str"), |
| 291 |
mask_length=dict(type="int"), |
| 292 |
mask_length4=dict(type="int"), |
| 293 |
mask_length6=dict(type="int"), |
| 294 |
subnet_mask=dict(type="str"), |
| 295 |
color=dict( |
| 296 |
type="str", |
| 297 |
choices=[ |
| 298 |
"aquamarine", |
| 299 |
"black", |
| 300 |
"blue", |
| 301 |
"crete blue", |
| 302 |
"burlywood", |
| 303 |
"cyan", |
| 304 |
"dark green", |
| 305 |
"khaki", |
| 306 |
"orchid", |
| 307 |
"dark orange", |
| 308 |
"dark sea green", |
| 309 |
"pink", |
| 310 |
"turquoise", |
| 311 |
"dark blue", |
| 312 |
"firebrick", |
| 313 |
"brown", |
| 314 |
"forest green", |
| 315 |
"gold", |
| 316 |
"dark gold", |
| 317 |
"gray", |
| 318 |
"dark gray", |
| 319 |
"light green", |
| 320 |
"lemon chiffon", |
| 321 |
"coral", |
| 322 |
"sea green", |
| 323 |
"sky blue", |
| 324 |
"magenta", |
| 325 |
"purple", |
| 326 |
"slate blue", |
| 327 |
"violet red", |
| 328 |
"navy blue", |
| 329 |
"olive", |
| 330 |
"orange", |
| 331 |
"red", |
| 332 |
"sienna", |
| 333 |
"yellow", |
| 334 |
], |
| 335 |
), |
| 336 |
comments=dict(type="str"), |
| 337 |
details_level=dict( |
| 338 |
type="str", choices=["uid", "standard", "full"] |
| 339 |
), |
| 340 |
ignore_warnings=dict(type="bool"), |
| 341 |
ignore_errors=dict(type="bool"), |
| 342 |
), |
| 343 |
), |
| 344 |
nat_settings=dict( |
| 345 |
type="dict", |
| 346 |
options=dict( |
| 347 |
auto_rule=dict(type="bool"), |
| 348 |
ip_address=dict(type="str"), |
| 349 |
ipv4_address=dict(type="str"), |
| 350 |
ipv6_address=dict(type="str"), |
| 351 |
hide_behind=dict( |
| 352 |
type="str", choices=["gateway", "ip-address"] |
| 353 |
), |
| 354 |
install_on=dict(type="str"), |
| 355 |
method=dict(type="str", choices=["hide", "static"]), |
| 356 |
), |
| 357 |
), |
| 358 |
tags=dict(type="list", elements="str"), |
| 359 |
host_servers=dict( |
| 360 |
type="dict", |
| 361 |
options=dict( |
| 362 |
dns_server=dict(type="bool"), |
| 363 |
mail_server=dict(type="bool"), |
| 364 |
web_server=dict(type="bool"), |
| 365 |
web_server_config=dict( |
| 366 |
type="dict", |
| 367 |
options=dict( |
| 368 |
additional_ports=dict(type="list", elements="str"), |
| 369 |
application_engines=dict(type="list", elements="str"), |
| 370 |
listen_standard_port=dict(type="bool"), |
| 371 |
operating_system=dict( |
| 372 |
type="str", |
| 373 |
choices=[ |
| 374 |
"sparc linux", |
| 375 |
"windows", |
| 376 |
"other", |
| 377 |
"x86 linux", |
| 378 |
"sparc solaris", |
| 379 |
], |
| 380 |
), |
| 381 |
protected_by=dict(type="str"), |
| 382 |
), |
| 383 |
), |
| 384 |
), |
| 385 |
), |
| 386 |
color=dict( |
| 387 |
type="str", |
| 388 |
choices=[ |
| 389 |
"aquamarine", |
| 390 |
"black", |
| 391 |
"blue", |
| 392 |
"crete blue", |
| 393 |
"burlywood", |
| 394 |
"cyan", |
| 395 |
"dark green", |
| 396 |
"khaki", |
| 397 |
"orchid", |
| 398 |
"dark orange", |
| 399 |
"dark sea green", |
| 400 |
"pink", |
| 401 |
"turquoise", |
| 402 |
"dark blue", |
| 403 |
"firebrick", |
| 404 |
"brown", |
| 405 |
"forest green", |
| 406 |
"gold", |
| 407 |
"dark gold", |
| 408 |
"gray", |
| 409 |
"dark gray", |
| 410 |
"light green", |
| 411 |
"lemon chiffon", |
| 412 |
"coral", |
| 413 |
"sea green", |
| 414 |
"sky blue", |
| 415 |
"magenta", |
| 416 |
"purple", |
| 417 |
"slate blue", |
| 418 |
"violet red", |
| 419 |
"navy blue", |
| 420 |
"olive", |
| 421 |
"orange", |
| 422 |
"red", |
| 423 |
"sienna", |
| 424 |
"yellow", |
| 425 |
], |
| 426 |
), |
| 427 |
comments=dict(type="str"), |
| 428 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 429 |
groups=dict(type="list", elements="str"), |
| 430 |
ignore_warnings=dict(type="bool"), |
| 431 |
ignore_errors=dict(type="bool"), |
| 432 |
) |
| 433 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 434 |
|
| 435 |
module = AnsibleModule( |
| 436 |
argument_spec=argument_spec, supports_check_mode=True |
| 437 |
) |
| 438 |
api_call_object = "host" |
| 439 |
|
| 440 |
result = api_call(module, api_call_object) |
| 441 |
module.exit_json(**result) |
| 442 |
|
| 443 |
|
| 444 |
if __name__ == "__main__": |
| 445 |
main() |