| 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 = {'metadata_version': '1.1', |
| 25 |
'status': ['preview'], |
| 26 |
'supported_by': 'community'} |
| 27 |
|
| 28 |
DOCUMENTATION = """ |
| 29 |
--- |
| 30 |
module: cp_mgmt_https_rule |
| 31 |
short_description: Manages https-rule objects on Checkpoint over Web Services API |
| 32 |
description: |
| 33 |
- Manages https-rule objects on Checkpoint devices including creating, updating and removing objects. |
| 34 |
- All operations are performed over Web Services API. |
| 35 |
- Available from R80.40 management version. |
| 36 |
version_added: "6.0.0" |
| 37 |
author: "Eden Brillant (@chkp-edenbr)" |
| 38 |
options: |
| 39 |
position: |
| 40 |
description: |
| 41 |
- Position in the rulebase. |
| 42 |
type: str |
| 43 |
layer: |
| 44 |
description: |
| 45 |
- Layer that holds the Object. Identified by the Name or UID. |
| 46 |
type: str |
| 47 |
name: |
| 48 |
description: |
| 49 |
- Rule name. |
| 50 |
type: str |
| 51 |
required: True |
| 52 |
destination: |
| 53 |
description: |
| 54 |
- Collection of Network objects identified by Name or UID that represents connection destination. |
| 55 |
type: list |
| 56 |
elements: str |
| 57 |
service: |
| 58 |
description: |
| 59 |
- Collection of Network objects identified by Name or UID that represents connection service. |
| 60 |
type: list |
| 61 |
elements: str |
| 62 |
source: |
| 63 |
description: |
| 64 |
- Collection of Network objects identified by Name or UID that represents connection source. |
| 65 |
type: list |
| 66 |
elements: str |
| 67 |
action: |
| 68 |
description: |
| 69 |
- Rule inspect level. "Bypass" or "Inspect". |
| 70 |
type: str |
| 71 |
blade: |
| 72 |
description: |
| 73 |
- Blades for HTTPS Inspection. Identified by Name or UID of the blade. |
| 74 |
type: list |
| 75 |
elements: str |
| 76 |
certificate: |
| 77 |
description: |
| 78 |
- Internal Server Certificate identified by Name or UID, otherwise, "Outbound Certificate" is a default value. |
| 79 |
type: str |
| 80 |
destination_negate: |
| 81 |
description: |
| 82 |
- TRUE if "negate" value is set for Destination. |
| 83 |
type: bool |
| 84 |
enabled: |
| 85 |
description: |
| 86 |
- Enable/Disable the rule. |
| 87 |
type: bool |
| 88 |
install_on: |
| 89 |
description: |
| 90 |
- Which Gateways identified by the name or UID to install the policy on. |
| 91 |
type: list |
| 92 |
elements: str |
| 93 |
service_negate: |
| 94 |
description: |
| 95 |
- TRUE if "negate" value is set for Service. |
| 96 |
type: bool |
| 97 |
site_category: |
| 98 |
description: |
| 99 |
- Collection of Site Categories objects identified by the name or UID. |
| 100 |
type: list |
| 101 |
elements: str |
| 102 |
site_category_negate: |
| 103 |
description: |
| 104 |
- TRUE if "negate" value is set for Site Category. |
| 105 |
type: bool |
| 106 |
source_negate: |
| 107 |
description: |
| 108 |
- TRUE if "negate" value is set for Source. |
| 109 |
type: bool |
| 110 |
tags: |
| 111 |
description: |
| 112 |
- Collection of tag identifiers. |
| 113 |
- Available from R81.20 JHF management version. |
| 114 |
type: list |
| 115 |
elements: str |
| 116 |
track: |
| 117 |
description: |
| 118 |
- a "None","Log","Alert","Mail","SNMP trap","Mail","User Alert 1", "User Alert 2", "User Alert 3". |
| 119 |
type: str |
| 120 |
comments: |
| 121 |
description: |
| 122 |
- Comments string. |
| 123 |
type: str |
| 124 |
details_level: |
| 125 |
description: |
| 126 |
- 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 |
| 127 |
representation of the object. |
| 128 |
type: str |
| 129 |
choices: ['uid', 'standard', 'full'] |
| 130 |
ignore_warnings: |
| 131 |
description: |
| 132 |
- Apply changes ignoring warnings. |
| 133 |
type: bool |
| 134 |
ignore_errors: |
| 135 |
description: |
| 136 |
- 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. |
| 137 |
type: bool |
| 138 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 139 |
""" |
| 140 |
|
| 141 |
EXAMPLES = """ |
| 142 |
- name: add-https-rule |
| 143 |
cp_mgmt_https_rule: |
| 144 |
layer: Default Outbound Layer |
| 145 |
name: FirstRule |
| 146 |
position: 1 |
| 147 |
state: present |
| 148 |
|
| 149 |
- name: set-https-rule |
| 150 |
cp_mgmt_https_rule: |
| 151 |
name: FirstRule |
| 152 |
position: 2 |
| 153 |
layer: Default Outbound Layer |
| 154 |
state: present |
| 155 |
|
| 156 |
- name: delete-https-rule |
| 157 |
cp_mgmt_https_rule: |
| 158 |
name: FirstRule |
| 159 |
layer: Default Outbound Layer |
| 160 |
state: absent |
| 161 |
""" |
| 162 |
|
| 163 |
RETURN = """ |
| 164 |
cp_mgmt_https_rule: |
| 165 |
description: The checkpoint object created or updated. |
| 166 |
returned: always, except when deleting the object. |
| 167 |
type: dict |
| 168 |
""" |
| 169 |
|
| 170 |
from ansible.module_utils.basic import AnsibleModule |
| 171 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call, api_call_for_rule |
| 172 |
|
| 173 |
|
| 174 |
def main(): |
| 175 |
argument_spec = dict( |
| 176 |
position=dict(type='str'), |
| 177 |
layer=dict(type='str'), |
| 178 |
name=dict(type='str', required=True), |
| 179 |
destination=dict(type='list', elements='str'), |
| 180 |
service=dict(type='list', elements='str'), |
| 181 |
source=dict(type='list', elements='str'), |
| 182 |
action=dict(type='str'), |
| 183 |
blade=dict(type='list', elements='str'), |
| 184 |
certificate=dict(type='str'), |
| 185 |
destination_negate=dict(type='bool'), |
| 186 |
enabled=dict(type='bool'), |
| 187 |
install_on=dict(type='list', elements='str'), |
| 188 |
service_negate=dict(type='bool'), |
| 189 |
site_category=dict(type='list', elements='str'), |
| 190 |
site_category_negate=dict(type='bool'), |
| 191 |
source_negate=dict(type='bool'), |
| 192 |
tags=dict(type='list', elements='str'), |
| 193 |
track=dict(type='str'), |
| 194 |
comments=dict(type='str'), |
| 195 |
details_level=dict(type='str', choices=['uid', 'standard', 'full']), |
| 196 |
ignore_warnings=dict(type='bool'), |
| 197 |
ignore_errors=dict(type='bool') |
| 198 |
) |
| 199 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 200 |
|
| 201 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 202 |
api_call_object = 'https-rule' |
| 203 |
|
| 204 |
if module.params["position"] is None: |
| 205 |
result = api_call(module, api_call_object) |
| 206 |
else: |
| 207 |
result = api_call_for_rule(module, api_call_object) |
| 208 |
|
| 209 |
module.exit_json(**result) |
| 210 |
|
| 211 |
|
| 212 |
if __name__ == '__main__': |
| 213 |
main() |