Skip to content

Commit eee21f4

Browse files
Merge pull request #42 from chkp-shirango/master
Add modules for multi-domains version and add an error message to tas…
2 parents a7695d5 + 7fdfaa0 commit eee21f4

12 files changed

+1499
-3
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This Ansible collection provides control over a Check Point Management server us
33
Check Point's web-services APIs.
44

55
The Ansible Check Point modules reference can be found here:
6-
https://docs.ansible.com/ansible/latest/modules/list_of_network_modules.html#check-point
6+
https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/index.html#plugins-in-check-point-mgmt
77
<br>Note - look only at the `cp_mgmt_*` modules, cause the `checkpoint_*` will be deprecated.
88

99
This is the repository of the mgmt collection which can be found here - https://galaxy.ansible.com/check_point/mgmt
@@ -119,6 +119,8 @@ Modules
119119
* `cp_mgmt_host` – Manages host objects on Check Point over Web Services API
120120
* `cp_mgmt_host_facts` – Get host objects facts on Check Point over Web Services API
121121
* `cp_mgmt_install_policy` – install policy on Check Point over Web Services API
122+
* `cp_mgmt_install_database` – install database on Check Point over Web Services API
123+
* `cp_mgmt_mds` – Multi-Domain Server (mds) objects on Check Point over Web Services API
122124
* `cp_mgmt_mds_facts` – Get Multi-Domain Server (mds) objects facts on Check Point over Web Services API
123125
* `cp_mgmt_multicast_address_range` – Manages multicast-address-range objects on Check Point over Web Services API
124126
* `cp_mgmt_multicast_address_range_facts` – Get multicast-address-range objects facts on Check Point over Web Services API
@@ -175,3 +177,11 @@ Modules
175177
* `cp_mgmt_vpn_community_star_facts` – Get vpn-community-star objects facts on Check Point over Web Services API
176178
* `cp_mgmt_wildcard` – Manages wildcard objects on Check Point over Web Services API
177179
* `cp_mgmt_wildcard_facts` – Get wildcard objects facts on Check Point over Web Services API
180+
* `cp_mgmt_add_domain` – Add new domain on Check Point over Web Services API
181+
* `cp_mgmt_set_domain` – Edit existing domain on Check Point over Web Services API
182+
* `cp_mgmt_delete_domain` – Delete existing domain on Check Point over Web Services API
183+
* `cp_mgmt_domain_facts` – Get domain objects on Check Point over Web Services API
184+
* `cp_mgmt_trusted_client` – Trusted client objects on Check Point over Web Services API
185+
* `cp_mgmt_trusted_client_facts` – Get trusted client objects facts on Check Point over Web Services API
186+
* `cp_mgmt_identity_tag` – Identity tag objects on Check Point over Web Services API
187+
* `cp_mgmt_identity_tag_facts` – Get identity tag objects facts on Check Point over Web Services API

plugins/module_utils/checkpoint.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ def wait_for_task(module, version, connection, task_id):
131131
completed_tasks = 0
132132
for task in response['tasks']:
133133
if task['status'] == 'failed':
134-
module.fail_json(msg='Task {0} with task id {1} failed. Look at the logs for more details'
135-
.format(task['task-name'], task['task-id']))
134+
if 'comments' in task and task['comments']:
135+
module.fail_json(msg='Task {0} with task id {1} failed. Message: {2} - Look at the logs for more '
136+
'details '
137+
.format(task['task-name'], task['task-id'], task['comments']))
138+
else:
139+
module.fail_json(msg='Task {0} with task id {1} failed. Look at the logs for more details'
140+
.format(task['task-name'], task['task-id']))
136141
if task['status'] == 'in progress':
137142
break
138143
completed_tasks += 1

plugins/modules/cp_mgmt_add_domain.py

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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_add_domain
31+
short_description: Manages domain objects on Checkpoint over Web Services API
32+
description:
33+
- Manages domain objects on Checkpoint devices including creating, updating and removing objects.
34+
- All operations are performed over Web Services API.
35+
version_added: "2.9"
36+
author: "Or Soffer (@chkp-orso)"
37+
options:
38+
name:
39+
description:
40+
- Object name.
41+
type: str
42+
required: True
43+
servers:
44+
description:
45+
- Domain servers. When this field is provided, 'set-domain' command is executed asynchronously.
46+
type: dict
47+
suboptions:
48+
description:
49+
- Adds to collection of values
50+
type: list
51+
suboptions:
52+
name:
53+
description:
54+
- Object name. Must be unique in the domain.
55+
type: str
56+
ip_address:
57+
description:
58+
- IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly.
59+
type: str
60+
ipv4_address:
61+
description:
62+
- IPv4 address.
63+
type: str
64+
ipv6_address:
65+
description:
66+
- IPv6 address.
67+
type: str
68+
multi_domain_server:
69+
description:
70+
- Multi Domain server name or UID.
71+
type: str
72+
skip_start_domain_server:
73+
description:
74+
- Set this value to be true to prevent starting the new created domain.
75+
type: bool
76+
type:
77+
description:
78+
- Domain server type.
79+
type: str
80+
choices: ['management server', 'log server', 'smc']
81+
color:
82+
description:
83+
- Color of the object. Should be one of existing colors.
84+
type: str
85+
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green',
86+
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon',
87+
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow']
88+
comments:
89+
description:
90+
- Comments string.
91+
type: str
92+
details_level:
93+
description:
94+
- 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
95+
representation of the object.
96+
type: str
97+
choices: ['uid', 'standard', 'full']
98+
ignore_warnings:
99+
description:
100+
- Apply changes ignoring warnings.
101+
type: bool
102+
ignore_errors:
103+
description:
104+
- 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.
105+
type: bool
106+
tags:
107+
description:
108+
- Collection of tag identifiers. Note, The list of tags can not be modified in a single command together with the domain servers. To modify
109+
tags, please use the separate 'set-domain' command, without providing the list of domain servers.
110+
type: list
111+
extends_documentation_fragment: checkpoint_objects
112+
"""
113+
114+
EXAMPLES = """
115+
- name: add-domain
116+
cp_mgmt_add_domain:
117+
name: domain1
118+
servers:
119+
ip_address: 192.0.2.1
120+
multi_domain_server: MDM_Server
121+
name: domain1_ManagementServer_1
122+
state: present
123+
"""
124+
125+
RETURN = """
126+
cp_mgmt_domain:
127+
description: The checkpoint object created or updated.
128+
returned: always, except when deleting the object.
129+
type: dict
130+
"""
131+
132+
from ansible.module_utils.basic import AnsibleModule
133+
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_commands, api_command
134+
135+
136+
def main():
137+
argument_spec = dict(
138+
name=dict(type='str', required=True),
139+
servers=dict(type='list', options=dict(
140+
name=dict(type='str'),
141+
ip_address=dict(type='str'),
142+
ipv4_address=dict(type='str'),
143+
ipv6_address=dict(type='str'),
144+
multi_domain_server=dict(type='str'),
145+
active=dict(type='bool'),
146+
skip_start_domain_server=dict(type='bool'),
147+
type=dict(type='str', choices=['management server', 'log server', 'smc'])
148+
)),
149+
color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green',
150+
'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown',
151+
'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green',
152+
'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna',
153+
'yellow']),
154+
comments=dict(type='str'),
155+
details_level=dict(type='str', choices=['uid', 'standard', 'full']),
156+
ignore_warnings=dict(type='bool'),
157+
ignore_errors=dict(type='bool'),
158+
tags=dict(type='list')
159+
)
160+
argument_spec.update(checkpoint_argument_spec_for_commands)
161+
162+
module = AnsibleModule(argument_spec=argument_spec)
163+
api_call_object = 'add-domain'
164+
165+
result = api_command(module, api_call_object)
166+
module.exit_json(**result)
167+
168+
169+
if __name__ == '__main__':
170+
main()
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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_delete_domain
31+
short_description: Manages domain objects on Checkpoint over Web Services API
32+
description:
33+
- Manages domain objects on Checkpoint devices including creating, updating and removing objects.
34+
- All operations are performed over Web Services API.
35+
version_added: "2.9"
36+
author: "Or Soffer (@chkp-orso)"
37+
options:
38+
name:
39+
description:
40+
- Object name.
41+
type: str
42+
required: True
43+
details_level:
44+
description:
45+
- 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
46+
representation of the object.
47+
type: str
48+
choices: ['uid', 'standard', 'full']
49+
ignore_warnings:
50+
description:
51+
- Apply changes ignoring warnings.
52+
type: bool
53+
ignore_errors:
54+
description:
55+
- 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.
56+
type: bool
57+
extends_documentation_fragment: checkpoint_objects
58+
"""
59+
60+
EXAMPLES = """
61+
- name: delete-domain
62+
cp_mgmt_delete_domain:
63+
name: domain1
64+
state: absent
65+
"""
66+
67+
RETURN = """
68+
cp_mgmt_domain:
69+
description: The checkpoint object created or updated.
70+
returned: always, except when deleting the object.
71+
type: dict
72+
"""
73+
74+
from ansible.module_utils.basic import AnsibleModule
75+
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_commands, api_command
76+
77+
78+
def main():
79+
argument_spec = dict(
80+
name=dict(type='str', required=True),
81+
details_level=dict(type='str', choices=['uid', 'standard', 'full']),
82+
ignore_warnings=dict(type='bool'),
83+
ignore_errors=dict(type='bool'),
84+
)
85+
argument_spec.update(checkpoint_argument_spec_for_commands)
86+
87+
module = AnsibleModule(argument_spec=argument_spec)
88+
api_call_object = 'delete-domain'
89+
90+
result = api_command(module, api_call_object)
91+
module.exit_json(**result)
92+
93+
94+
if __name__ == '__main__':
95+
main()

0 commit comments

Comments
 (0)