| 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_if_map_server |
| 31 |
short_description: Manages if-map-server objects on Checkpoint over Web Services API |
| 32 |
description: |
| 33 |
- Manages if-map-server objects on Checkpoint devices including creating, updating and removing objects. |
| 34 |
- All operations are performed over Web Services API. |
| 35 |
- Available from R82 JHF management version. |
| 36 |
version_added: "6.5.0" |
| 37 |
author: "Dor Berenstein (@chkp-dorbe)" |
| 38 |
options: |
| 39 |
name: |
| 40 |
description: |
| 41 |
- Object name. |
| 42 |
type: str |
| 43 |
required: True |
| 44 |
host: |
| 45 |
description: |
| 46 |
- Host that is IF-MAP server. Identified by name or UID. |
| 47 |
type: str |
| 48 |
monitored_ips: |
| 49 |
description: |
| 50 |
- IP ranges to be monitored by the IF-MAP client. |
| 51 |
type: list |
| 52 |
elements: dict |
| 53 |
suboptions: |
| 54 |
first_ip: |
| 55 |
description: |
| 56 |
- First IPv4 address in the range to be monitored. |
| 57 |
type: str |
| 58 |
last_ip: |
| 59 |
description: |
| 60 |
- Last IPv4 address in the range to be monitored. |
| 61 |
type: str |
| 62 |
port: |
| 63 |
description: |
| 64 |
- IF-MAP server port number. |
| 65 |
type: int |
| 66 |
server_version: |
| 67 |
description: |
| 68 |
- IF-MAP version. |
| 69 |
type: str |
| 70 |
choices: ['2.0', '1.1'] |
| 71 |
path: |
| 72 |
description: |
| 73 |
- N/A |
| 74 |
type: str |
| 75 |
query_whole_ranges: |
| 76 |
description: |
| 77 |
- Indicate whether to query whole ranges instead of single IP. |
| 78 |
type: bool |
| 79 |
authentication: |
| 80 |
description: |
| 81 |
- Authentication configuration for the IF-MAP server. |
| 82 |
type: dict |
| 83 |
suboptions: |
| 84 |
authentication_method: |
| 85 |
description: |
| 86 |
- Authentication method for the IF-MAP server. |
| 87 |
type: str |
| 88 |
choices: ['certificate_based', 'basic'] |
| 89 |
username: |
| 90 |
description: |
| 91 |
- Username for the IF-MAP server authentication. <font color="red">Required only when</font> 'authentication-method' is set to 'basic'. |
| 92 |
type: str |
| 93 |
password: |
| 94 |
description: |
| 95 |
- Username for the IF-MAP server authentication. <font color="red">Required only when</font> 'authentication-method' is set to 'basic'. |
| 96 |
type: str |
| 97 |
color: |
| 98 |
description: |
| 99 |
- Color of the object. Should be one of existing colors. |
| 100 |
type: str |
| 101 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 102 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 103 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 104 |
comments: |
| 105 |
description: |
| 106 |
- Comments string. |
| 107 |
type: str |
| 108 |
details_level: |
| 109 |
description: |
| 110 |
- 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 |
| 111 |
representation of the object. |
| 112 |
type: str |
| 113 |
choices: ['uid', 'standard', 'full'] |
| 114 |
domains_to_process: |
| 115 |
description: |
| 116 |
- Indicates which domains to process the commands on. It cannot be used with the details-level full, must be run from the System Domain only and |
| 117 |
with ignore-warnings true. Valid values are, CURRENT_DOMAIN, ALL_DOMAINS_ON_THIS_SERVER. |
| 118 |
type: list |
| 119 |
elements: str |
| 120 |
tags: |
| 121 |
description: |
| 122 |
- Collection of tag identifiers. |
| 123 |
type: list |
| 124 |
elements: str |
| 125 |
ignore_warnings: |
| 126 |
description: |
| 127 |
- Apply changes ignoring warnings. |
| 128 |
type: bool |
| 129 |
ignore_errors: |
| 130 |
description: |
| 131 |
- 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. |
| 132 |
type: bool |
| 133 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 134 |
""" |
| 135 |
|
| 136 |
EXAMPLES = """ |
| 137 |
- name: add-if-map-server |
| 138 |
cp_mgmt_if_map_server: |
| 139 |
authentication: |
| 140 |
authentication_method: certificate_based |
| 141 |
host: TestHost |
| 142 |
monitored_ips: |
| 143 |
- first_ip: 1.1.1.1 |
| 144 |
last_ip: 1.1.1.2 |
| 145 |
- first_ip: 2.1.1.1 |
| 146 |
last_ip: 2.1.1.2 |
| 147 |
name: TestIfMapServer |
| 148 |
path: path |
| 149 |
port: 1 |
| 150 |
state: present |
| 151 |
version: 2 |
| 152 |
|
| 153 |
- name: set-if-map-server |
| 154 |
cp_mgmt_if_map_server: |
| 155 |
host: TestHost2 |
| 156 |
monitored_ips: |
| 157 |
- first_ip: 3.1.1.1 |
| 158 |
last_ip: 3.1.1.2 |
| 159 |
name: TestIfMapServer |
| 160 |
path: newPath |
| 161 |
port: 2 |
| 162 |
query_whole_ranges: false |
| 163 |
state: present |
| 164 |
version: 1.1 |
| 165 |
|
| 166 |
- name: delete-if-map-server |
| 167 |
cp_mgmt_if_map_server: |
| 168 |
name: TestIdp |
| 169 |
state: absent |
| 170 |
""" |
| 171 |
|
| 172 |
RETURN = """ |
| 173 |
cp_mgmt_if_map_server: |
| 174 |
description: The checkpoint object created or updated. |
| 175 |
returned: always, except when deleting the object. |
| 176 |
type: dict |
| 177 |
""" |
| 178 |
|
| 179 |
from ansible.module_utils.basic import AnsibleModule |
| 180 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call |
| 181 |
|
| 182 |
|
| 183 |
def main(): |
| 184 |
argument_spec = dict( |
| 185 |
name=dict(type='str', required=True), |
| 186 |
host=dict(type='str'), |
| 187 |
monitored_ips=dict(type='list', elements="dict", options=dict( |
| 188 |
first_ip=dict(type='str'), |
| 189 |
last_ip=dict(type='str') |
| 190 |
)), |
| 191 |
port=dict(type='int'), |
| 192 |
server_version=dict(type='str', choices=['2.0', '1.1']), |
| 193 |
path=dict(type='str'), |
| 194 |
query_whole_ranges=dict(type='bool'), |
| 195 |
authentication=dict(type='dict', options=dict( |
| 196 |
authentication_method=dict(type='str', choices=['certificate_based', 'basic']), |
| 197 |
username=dict(type='str'), |
| 198 |
password=dict(type='str', no_log=True) |
| 199 |
)), |
| 200 |
color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', |
| 201 |
'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', |
| 202 |
'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green', |
| 203 |
'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', |
| 204 |
'yellow']), |
| 205 |
comments=dict(type='str'), |
| 206 |
details_level=dict(type='str', choices=['uid', 'standard', 'full']), |
| 207 |
domains_to_process=dict(type='list', elements="str"), |
| 208 |
tags=dict(type='list', elements="str"), |
| 209 |
ignore_warnings=dict(type='bool'), |
| 210 |
ignore_errors=dict(type='bool') |
| 211 |
) |
| 212 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 213 |
|
| 214 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 215 |
api_call_object = 'if-map-server' |
| 216 |
|
| 217 |
result = api_call(module, api_call_object) |
| 218 |
module.exit_json(**result) |
| 219 |
|
| 220 |
|
| 221 |
if __name__ == '__main__': |
| 222 |
main() |