| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage CheckPoint 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": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_lsm_gateway |
| 33 |
short_description: Manages lsm-gateway objects on Checkpoint over Web Services API |
| 34 |
description: |
| 35 |
- Manages lsm-gateway objects on Checkpoint devices including creating, updating and removing objects. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- Available from R81.10 management version. |
| 38 |
version_added: "2.3.0" |
| 39 |
author: "Shiran Golzar (@chkp-shirango)" |
| 40 |
options: |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Object name. |
| 44 |
type: str |
| 45 |
required: True |
| 46 |
security_profile: |
| 47 |
description: |
| 48 |
- LSM profile. |
| 49 |
type: str |
| 50 |
device_id: |
| 51 |
description: |
| 52 |
- Device ID. |
| 53 |
- Available from R81.20 management version. |
| 54 |
type: str |
| 55 |
version_added: "6.3.0" |
| 56 |
dynamic_objects: |
| 57 |
description: |
| 58 |
- Dynamic Objects. |
| 59 |
- Available from R81.20 management version. |
| 60 |
type: list |
| 61 |
elements: dict |
| 62 |
version_added: "6.3.0" |
| 63 |
suboptions: |
| 64 |
name: |
| 65 |
description: |
| 66 |
- Object name. Must be unique in the domain. |
| 67 |
type: str |
| 68 |
resolved_ip_addresses: |
| 69 |
description: |
| 70 |
- Single IP-address or a range of addresses. |
| 71 |
type: list |
| 72 |
elements: dict |
| 73 |
suboptions: |
| 74 |
ipv4_address: |
| 75 |
description: |
| 76 |
- IPv4 Address. |
| 77 |
type: str |
| 78 |
ipv4_address_range: |
| 79 |
description: |
| 80 |
- IPv4 Address range. |
| 81 |
type: dict |
| 82 |
suboptions: |
| 83 |
from_ipv4_address: |
| 84 |
description: |
| 85 |
- First IPv4 address of the IP address range. |
| 86 |
type: str |
| 87 |
to_ipv4_address: |
| 88 |
description: |
| 89 |
- Last IPv4 address of the IP address range. |
| 90 |
type: str |
| 91 |
provisioning_settings: |
| 92 |
description: |
| 93 |
- Provisioning settings. |
| 94 |
type: dict |
| 95 |
suboptions: |
| 96 |
provisioning_profile: |
| 97 |
description: |
| 98 |
- Provisioning profile. |
| 99 |
type: str |
| 100 |
provisioning_state: |
| 101 |
description: |
| 102 |
- Provisioning state. By default the state is 'manual'- enable provisioning but not attach to profile. |
| 103 |
- If 'using-profile' state is provided a provisioning profile must be provided in provisioning-settings. |
| 104 |
type: str |
| 105 |
choices: ['off', 'manual', 'using-profile'] |
| 106 |
sic: |
| 107 |
description: |
| 108 |
- Secure Internal Communication. |
| 109 |
type: dict |
| 110 |
suboptions: |
| 111 |
ip_address: |
| 112 |
description: |
| 113 |
- IP address. When IP address is provided- initiate trusted communication immediately using this IP address. |
| 114 |
type: str |
| 115 |
one_time_password: |
| 116 |
description: |
| 117 |
- One-time password. When one-time password is provided without ip-address- trusted communication is automatically initiated when the |
| 118 |
gateway connects to the Security Management server for the first time. |
| 119 |
type: str |
| 120 |
topology: |
| 121 |
description: |
| 122 |
- Topology. |
| 123 |
- Available from R81.20 management version. |
| 124 |
type: dict |
| 125 |
version_added: "6.3.0" |
| 126 |
suboptions: |
| 127 |
manual_vpn_domain: |
| 128 |
description: |
| 129 |
- A list of IP-addresses ranges, defined the VPN community network. |
| 130 |
- This field is relevant only when 'manual' option of vpn-domain is checked. |
| 131 |
type: list |
| 132 |
elements: dict |
| 133 |
suboptions: |
| 134 |
comments: |
| 135 |
description: |
| 136 |
- Comments string. |
| 137 |
type: str |
| 138 |
from_ipv4_address: |
| 139 |
description: |
| 140 |
- First IPv4 address of the IP address range. |
| 141 |
type: str |
| 142 |
to_ipv4_address: |
| 143 |
description: |
| 144 |
- Last IPv4 address of the IP address range. |
| 145 |
type: str |
| 146 |
vpn_domain: |
| 147 |
description: |
| 148 |
- VPN Domain type. 'external-interfaces-only' is relevnt only for Gaia devices. |
| 149 |
'hide-behind-gateway-external-ip-address' is relevant only for SMB devices. |
| 150 |
type: str |
| 151 |
choices: ['not-defined', 'external-ip-addresses-only', 'hide-behind-gateway-external-ip-address', 'all-ip-addresses-behind-the-gateway', 'manual'] |
| 152 |
color: |
| 153 |
description: |
| 154 |
- Color of the object. Should be one of existing colors. |
| 155 |
type: str |
| 156 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 157 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 158 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 159 |
comments: |
| 160 |
description: |
| 161 |
- Comments string. |
| 162 |
type: str |
| 163 |
details_level: |
| 164 |
description: |
| 165 |
- 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 |
| 166 |
representation of the object. |
| 167 |
type: str |
| 168 |
choices: ['uid', 'standard', 'full'] |
| 169 |
tags: |
| 170 |
description: |
| 171 |
- Collection of tag identifiers. |
| 172 |
type: list |
| 173 |
elements: str |
| 174 |
version_added: "6.3.0" |
| 175 |
ignore_warnings: |
| 176 |
description: |
| 177 |
- Apply changes ignoring warnings. |
| 178 |
type: bool |
| 179 |
ignore_errors: |
| 180 |
description: |
| 181 |
- 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. |
| 182 |
type: bool |
| 183 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 184 |
""" |
| 185 |
|
| 186 |
EXAMPLES = """ |
| 187 |
- name: add-lsm-gateway |
| 188 |
cp_mgmt_lsm_gateway: |
| 189 |
name: lsm_gateway |
| 190 |
provisioning_settings: |
| 191 |
provisioning_profile: prv_profile |
| 192 |
provisioning_state: using-profile |
| 193 |
security_profile: lsm_profile |
| 194 |
sic: |
| 195 |
ip_address: 1.2.3.4 |
| 196 |
one_time_password: aaaa |
| 197 |
state: present |
| 198 |
|
| 199 |
- name: set-lsm-gateway |
| 200 |
cp_mgmt_lsm_gateway: |
| 201 |
name: lsm_gateway |
| 202 |
provisioning_settings: |
| 203 |
provisioning_profile: prv_profile |
| 204 |
provisioning_state: using-profile |
| 205 |
security_profile: lsm_profile |
| 206 |
sic: |
| 207 |
ip_address: 1.2.3.4 |
| 208 |
one_time_password: aaaa |
| 209 |
state: present |
| 210 |
|
| 211 |
- name: delete-lsm-gateway |
| 212 |
cp_mgmt_lsm_gateway: |
| 213 |
name: lsm_gateway |
| 214 |
state: absent |
| 215 |
""" |
| 216 |
|
| 217 |
RETURN = """ |
| 218 |
cp_mgmt_lsm_gateway: |
| 219 |
description: The checkpoint object created or updated. |
| 220 |
returned: always, except when deleting the object. |
| 221 |
type: dict |
| 222 |
""" |
| 223 |
|
| 224 |
from ansible.module_utils.basic import AnsibleModule |
| 225 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 226 |
checkpoint_argument_spec_for_objects, |
| 227 |
api_call, |
| 228 |
) |
| 229 |
|
| 230 |
|
| 231 |
def main(): |
| 232 |
argument_spec = dict( |
| 233 |
name=dict(type="str", required=True), |
| 234 |
security_profile=dict(type="str"), |
| 235 |
device_id=dict(type='str'), |
| 236 |
dynamic_objects=dict(type='list', elements="dict", options=dict( |
| 237 |
name=dict(type='str'), |
| 238 |
resolved_ip_addresses=dict(type='list', elements="dict", options=dict( |
| 239 |
ipv4_address=dict(type='str'), |
| 240 |
ipv4_address_range=dict(type='dict', options=dict( |
| 241 |
from_ipv4_address=dict(type='str'), |
| 242 |
to_ipv4_address=dict(type='str') |
| 243 |
)) |
| 244 |
)) |
| 245 |
)), |
| 246 |
provisioning_settings=dict( |
| 247 |
type="dict", options=dict(provisioning_profile=dict(type="str")) |
| 248 |
), |
| 249 |
provisioning_state=dict( |
| 250 |
type="str", choices=["off", "manual", "using-profile"] |
| 251 |
), |
| 252 |
sic=dict( |
| 253 |
type="dict", |
| 254 |
options=dict( |
| 255 |
ip_address=dict(type="str"), |
| 256 |
one_time_password=dict(type="str", no_log=True), |
| 257 |
), |
| 258 |
), |
| 259 |
topology=dict(type='dict', options=dict( |
| 260 |
manual_vpn_domain=dict(type='list', elements="dict", options=dict( |
| 261 |
comments=dict(type='str'), |
| 262 |
from_ipv4_address=dict(type='str'), |
| 263 |
to_ipv4_address=dict(type='str') |
| 264 |
)), |
| 265 |
vpn_domain=dict(type='str', choices=['not-defined', |
| 266 |
'external-ip-addresses-only', |
| 267 |
'hide-behind-gateway-external-ip-address', |
| 268 |
'all-ip-addresses-behind-the-gateway', |
| 269 |
'manual']) |
| 270 |
)), |
| 271 |
color=dict( |
| 272 |
type="str", |
| 273 |
choices=[ |
| 274 |
"aquamarine", |
| 275 |
"black", |
| 276 |
"blue", |
| 277 |
"crete blue", |
| 278 |
"burlywood", |
| 279 |
"cyan", |
| 280 |
"dark green", |
| 281 |
"khaki", |
| 282 |
"orchid", |
| 283 |
"dark orange", |
| 284 |
"dark sea green", |
| 285 |
"pink", |
| 286 |
"turquoise", |
| 287 |
"dark blue", |
| 288 |
"firebrick", |
| 289 |
"brown", |
| 290 |
"forest green", |
| 291 |
"gold", |
| 292 |
"dark gold", |
| 293 |
"gray", |
| 294 |
"dark gray", |
| 295 |
"light green", |
| 296 |
"lemon chiffon", |
| 297 |
"coral", |
| 298 |
"sea green", |
| 299 |
"sky blue", |
| 300 |
"magenta", |
| 301 |
"purple", |
| 302 |
"slate blue", |
| 303 |
"violet red", |
| 304 |
"navy blue", |
| 305 |
"olive", |
| 306 |
"orange", |
| 307 |
"red", |
| 308 |
"sienna", |
| 309 |
"yellow", |
| 310 |
], |
| 311 |
), |
| 312 |
comments=dict(type="str"), |
| 313 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 314 |
tags=dict(type="list", elements="str"), |
| 315 |
ignore_warnings=dict(type="bool"), |
| 316 |
ignore_errors=dict(type="bool"), |
| 317 |
) |
| 318 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 319 |
|
| 320 |
module = AnsibleModule( |
| 321 |
argument_spec=argument_spec, supports_check_mode=True |
| 322 |
) |
| 323 |
api_call_object = "lsm-gateway" |
| 324 |
|
| 325 |
result = api_call(module, api_call_object) |
| 326 |
module.exit_json(**result) |
| 327 |
|
| 328 |
|
| 329 |
if __name__ == "__main__": |
| 330 |
main() |