| 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_nat_rule |
| 31 |
short_description: Manages nat-rule objects on Checkpoint over Web Services API. |
| 32 |
description: |
| 33 |
- Manages nat-rule objects on Checkpoint devices including creating, updating and removing objects. |
| 34 |
- Minimum version required is 1.7.1 and JHF with PMTR-88097. |
| 35 |
- All operations are performed over Web Services API. |
| 36 |
- Available from R80 management version. |
| 37 |
version_added: "5.0.0" |
| 38 |
author: "Eden Brillant (@chkp-edenbr)" |
| 39 |
options: |
| 40 |
package: |
| 41 |
description: |
| 42 |
- Name of the package. |
| 43 |
- Available from R80.10 management version. |
| 44 |
type: str |
| 45 |
position: |
| 46 |
description: |
| 47 |
- Position in the rulebase. The use of values "top" and "bottom" may not be idempotent. |
| 48 |
type: str |
| 49 |
relative_position: |
| 50 |
description: |
| 51 |
- Position in the rulebase. |
| 52 |
- Use of this field may not be idempotent. |
| 53 |
type: dict |
| 54 |
suboptions: |
| 55 |
below: |
| 56 |
description: |
| 57 |
- Add rule below specific rule/section identified by name (limited to 50 rules if |
| 58 |
search_entire_rulebase is False). |
| 59 |
type: str |
| 60 |
above: |
| 61 |
description: |
| 62 |
- Add rule above specific rule/section identified by name (limited to 50 rules if |
| 63 |
search_entire_rulebase is False). |
| 64 |
type: str |
| 65 |
top: |
| 66 |
description: |
| 67 |
- Add rule to the top of a specific section identified by name (limited to 50 rules if |
| 68 |
search_entire_rulebase is False). |
| 69 |
type: str |
| 70 |
bottom: |
| 71 |
description: |
| 72 |
- Add rule to the bottom of a specific section identified by name (limited to 50 rules if |
| 73 |
search_entire_rulebase is False). |
| 74 |
type: str |
| 75 |
search_entire_rulebase: |
| 76 |
description: |
| 77 |
- Whether to search the entire rulebase for a rule that's been edited in its relative_position field to make sure |
| 78 |
there indeed has been a change in its position or the section it might be in. |
| 79 |
type: bool |
| 80 |
default: False |
| 81 |
name: |
| 82 |
description: |
| 83 |
- Rule name. |
| 84 |
- Available from R81 management version. |
| 85 |
type: str |
| 86 |
required: True |
| 87 |
enabled: |
| 88 |
description: |
| 89 |
- Enable/Disable the rule. |
| 90 |
type: bool |
| 91 |
install_on: |
| 92 |
description: |
| 93 |
- Which Gateways identified by the name or UID to install the policy on. |
| 94 |
type: list |
| 95 |
elements: str |
| 96 |
method: |
| 97 |
description: |
| 98 |
- Nat method. |
| 99 |
type: str |
| 100 |
choices: ['static', 'hide', 'nat64', 'nat46', 'cgnat'] |
| 101 |
original_destination: |
| 102 |
description: |
| 103 |
- Original destination. |
| 104 |
type: str |
| 105 |
original_service: |
| 106 |
description: |
| 107 |
- Original service. |
| 108 |
type: str |
| 109 |
original_source: |
| 110 |
description: |
| 111 |
- Original source. |
| 112 |
type: str |
| 113 |
translated_destination: |
| 114 |
description: |
| 115 |
- Translated destination. |
| 116 |
type: str |
| 117 |
translated_service: |
| 118 |
description: |
| 119 |
- Translated service. |
| 120 |
type: str |
| 121 |
translated_source: |
| 122 |
description: |
| 123 |
- Translated source. |
| 124 |
type: str |
| 125 |
comments: |
| 126 |
description: |
| 127 |
- Comments string. |
| 128 |
type: str |
| 129 |
details_level: |
| 130 |
description: |
| 131 |
- 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 |
| 132 |
representation of the object. |
| 133 |
type: str |
| 134 |
choices: ['uid', 'standard', 'full'] |
| 135 |
ignore_warnings: |
| 136 |
description: |
| 137 |
- Apply changes ignoring warnings. |
| 138 |
type: bool |
| 139 |
ignore_errors: |
| 140 |
description: |
| 141 |
- 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. |
| 142 |
type: bool |
| 143 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 144 |
""" |
| 145 |
|
| 146 |
EXAMPLES = """ |
| 147 |
- name: add-nat-rule |
| 148 |
cp_mgmt_nat_rule: |
| 149 |
name: nat_rule1 |
| 150 |
comments: comment example1 nat999 |
| 151 |
enabled: false |
| 152 |
install_on: |
| 153 |
- Policy Targets |
| 154 |
original_destination: All_Internet |
| 155 |
original_source: Any |
| 156 |
package: standard |
| 157 |
position: 1 |
| 158 |
state: present |
| 159 |
|
| 160 |
- name: set-nat-rule |
| 161 |
cp_mgmt_nat_rule: |
| 162 |
name: nat_rule1 |
| 163 |
comments: rule for RND members RNDNetwork-> RND to Internal Network |
| 164 |
enabled: false |
| 165 |
original_service: ssh_version_2 |
| 166 |
original_source: Any |
| 167 |
package: standard |
| 168 |
state: present |
| 169 |
|
| 170 |
- name: delete-nat-rule |
| 171 |
cp_mgmt_nat_rule: |
| 172 |
name: nat_rule1 |
| 173 |
package: standard |
| 174 |
state: absent |
| 175 |
""" |
| 176 |
|
| 177 |
RETURN = """ |
| 178 |
cp_mgmt_nat_rule: |
| 179 |
description: The checkpoint object created or updated. |
| 180 |
returned: always, except when deleting the object. |
| 181 |
type: dict |
| 182 |
""" |
| 183 |
|
| 184 |
from ansible.module_utils.basic import AnsibleModule |
| 185 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call_for_rule |
| 186 |
|
| 187 |
|
| 188 |
def main(): |
| 189 |
argument_spec = dict( |
| 190 |
package=dict(type='str'), |
| 191 |
position=dict(type='str'), |
| 192 |
relative_position=dict(type='dict', options=dict( |
| 193 |
below=dict(type='str'), |
| 194 |
above=dict(type='str'), |
| 195 |
top=dict(type='str'), |
| 196 |
bottom=dict(type='str') |
| 197 |
)), |
| 198 |
search_entire_rulebase=dict(type='bool', default=False), |
| 199 |
name=dict(type='str', required=True), |
| 200 |
enabled=dict(type='bool'), |
| 201 |
install_on=dict(type='list', elements='str'), |
| 202 |
method=dict(type='str', choices=['static', 'hide', 'nat64', 'nat46', 'cgnat']), |
| 203 |
original_destination=dict(type='str'), |
| 204 |
original_service=dict(type='str'), |
| 205 |
original_source=dict(type='str'), |
| 206 |
translated_destination=dict(type='str'), |
| 207 |
translated_service=dict(type='str'), |
| 208 |
translated_source=dict(type='str'), |
| 209 |
comments=dict(type='str'), |
| 210 |
details_level=dict(type='str', choices=['uid', 'standard', 'full']), |
| 211 |
ignore_warnings=dict(type='bool'), |
| 212 |
ignore_errors=dict(type='bool') |
| 213 |
) |
| 214 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 215 |
|
| 216 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 217 |
api_call_object = 'nat-rule' |
| 218 |
|
| 219 |
if module.params["relative_position"] is not None: |
| 220 |
if module.params["position"] is not None: |
| 221 |
raise AssertionError("The use of both 'relative_position' and 'position' arguments isn't allowed") |
| 222 |
module.params["position"] = module.params["relative_position"] |
| 223 |
module.params.pop("relative_position") |
| 224 |
|
| 225 |
result = api_call_for_rule(module, api_call_object) |
| 226 |
module.exit_json(**result) |
| 227 |
|
| 228 |
|
| 229 |
if __name__ == '__main__': |
| 230 |
main() |