Skip to content

Commit 0d2f4ec

Browse files
committed
version 1.0.6
1 parent a531deb commit 0d2f4ec

23 files changed

+1642
-17
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Note - If you want to run against Ansible version 2.9 instead of the collection,
7070
2. Ansible has a feature called "Check Mode" that enables you to test the
7171
changes without actually changing anything.
7272
3. The login and logout happens automatically.
73-
4. If you want to login to a specific domain, in the playbook above, in the `vars`secion, in
74-
`ansible_checkpoint_domain` key, change the value from `SMC User` to `YOUR_DOMAIN`
73+
4. If you want to login to a specific domain, in the playbook above in the `vars`secion change the domain name to
74+
`ansible_checkpoint_domain`
7575
5. There are two ways to publish changes:
7676
a. Set the `auto_publish_session` to `true` as displayed in the example playbook above.
7777
This option will publish only the task which this parameter belongs to.
@@ -81,6 +81,8 @@ Note - If you want to run against Ansible version 2.9 instead of the collection,
8181
7. If you still want to use Ansible version 2.9 instead of this collection (not recommended):
8282
a. In the `hosts` file replace `ansible_network_os=check_point.mgmt.checkpoint` with `ansible_network_os=checkpoint`
8383
b. In the task in the playbook replace the module `check_point.mgmt.cp_mgmt_*` with the module `cp_mgmt_*`
84+
8. Starting from version 1.0.6, when running a command which returns a task-id, and the user chooses to wait for that task to finish
85+
(the default is to wait), then the output of the command will be the output of the show-task command (instead of the task-id).
8486

8587
Modules
8688
-------

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: check_point
99
name: mgmt
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 1.0.5
12+
version: 1.0.6
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md

plugins/module_utils/checkpoint.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def get_payload_from_parameters(params):
9999

100100
# wait for task
101101
def wait_for_task(module, version, connection, task_id):
102-
task_id_payload = {'task-id': task_id}
102+
task_id_payload = {'task-id': task_id, 'details-level': 'full'}
103103
task_complete = False
104104
current_iteration = 0
105105
max_num_iterations = 300
@@ -138,6 +138,8 @@ def wait_for_task(module, version, connection, task_id):
138138
time.sleep(2) # Wait for two seconds
139139
if not task_complete:
140140
module.fail_json(msg="ERROR: Timeout. Task-id: {0}.".format(task_id_payload['task-id']))
141+
else:
142+
return response
141143

142144

143145
# if failed occurred, in some cases we want to discard changes before exiting. We also notify the user about the `discard`
@@ -199,7 +201,7 @@ def api_command(module, command):
199201
if code == 200:
200202
if module.params['wait_for_task']:
201203
if 'task-id' in response:
202-
wait_for_task(module, version, connection, response['task-id'])
204+
response = wait_for_task(module, version, connection, response['task-id'])
203205
elif 'tasks' in response:
204206
for task in response['tasks']:
205207
if 'task-id' in task:
@@ -428,14 +430,29 @@ def api_call_for_rule(module, api_call_object):
428430
return result
429431

430432

433+
# check if call is in plural form
434+
def call_is_plural(api_call_object, payload):
435+
is_plural = False
436+
if 'access' in api_call_object and payload.get("layer") is None:
437+
is_plural = True
438+
elif 'threat' in api_call_object and payload.get("layer") is None:
439+
is_plural = True
440+
elif 'nat' in api_call_object \
441+
and payload.get("name") is None \
442+
and payload.get("uid") is None \
443+
and payload.get("rule-number") is None:
444+
is_plural = True
445+
return is_plural
446+
447+
431448
# handle api call facts for rule
432449
def api_call_facts_for_rule(module, api_call_object, api_call_object_plural_version):
433450
payload = get_payload_from_parameters(module.params)
434451
connection = Connection(module._socket_path)
435452
version = get_version(module)
436453

437454
# if there is no layer, the API command will be in plural version (e.g. show-hosts instead of show-host)
438-
if payload.get("layer") is None:
455+
if call_is_plural(api_call_object, payload):
439456
api_call_object = api_call_object_plural_version
440457

441458
response = handle_call(connection, version, 'show-' + api_call_object, payload, module, False, False)
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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_nat_rule
31+
short_description: Create new object.
32+
description:
33+
- Create new object.
34+
- All operations are performed over Web Services API.
35+
version_added: "2.9"
36+
author: "Or Soffer (@chkp-orso)"
37+
options:
38+
package:
39+
description:
40+
- Name of the package.
41+
type: str
42+
position:
43+
description:
44+
- Position in the rulebase.
45+
type: str
46+
enabled:
47+
description:
48+
- Enable/Disable the rule.
49+
type: bool
50+
install_on:
51+
description:
52+
- Which Gateways identified by the name or UID to install the policy on.
53+
type: list
54+
method:
55+
description:
56+
- Nat method.
57+
type: str
58+
choices: ['static', 'hide', 'nat64', 'nat46']
59+
original_destination:
60+
description:
61+
- Original destination.
62+
type: str
63+
original_service:
64+
description:
65+
- Original service.
66+
type: str
67+
original_source:
68+
description:
69+
- Original source.
70+
type: str
71+
translated_destination:
72+
description:
73+
- Translated destination.
74+
type: str
75+
translated_service:
76+
description:
77+
- Translated service.
78+
type: str
79+
translated_source:
80+
description:
81+
- Translated source.
82+
type: str
83+
comments:
84+
description:
85+
- Comments string.
86+
type: str
87+
details_level:
88+
description:
89+
- 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
90+
representation of the object.
91+
type: str
92+
choices: ['uid', 'standard', 'full']
93+
ignore_warnings:
94+
description:
95+
- Apply changes ignoring warnings.
96+
type: bool
97+
ignore_errors:
98+
description:
99+
- 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.
100+
type: bool
101+
extends_documentation_fragment: check_point.mgmt.checkpoint_commands
102+
"""
103+
104+
EXAMPLES = """
105+
- name: add-nat-rule
106+
cp_mgmt_add_nat_rule:
107+
comments: comment example1 nat999
108+
enabled: false
109+
install_on:
110+
- Policy Targets
111+
original_destination: All_Internet
112+
original_source: Any
113+
package: standard
114+
position: 1
115+
state: present
116+
"""
117+
118+
RETURN = """
119+
cp_mgmt_add_nat_rule:
120+
description: The checkpoint add-nat-rule output.
121+
returned: always.
122+
type: dict
123+
"""
124+
125+
from ansible.module_utils.basic import AnsibleModule
126+
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_commands, api_command
127+
128+
129+
def main():
130+
argument_spec = dict(
131+
package=dict(type='str'),
132+
position=dict(type='str'),
133+
enabled=dict(type='bool'),
134+
install_on=dict(type='list'),
135+
method=dict(type='str', choices=['static', 'hide', 'nat64', 'nat46']),
136+
original_destination=dict(type='str'),
137+
original_service=dict(type='str'),
138+
original_source=dict(type='str'),
139+
translated_destination=dict(type='str'),
140+
translated_service=dict(type='str'),
141+
translated_source=dict(type='str'),
142+
comments=dict(type='str'),
143+
details_level=dict(type='str', choices=['uid', 'standard', 'full']),
144+
ignore_warnings=dict(type='bool'),
145+
ignore_errors=dict(type='bool')
146+
)
147+
argument_spec.update(checkpoint_argument_spec_for_commands)
148+
149+
module = AnsibleModule(argument_spec=argument_spec)
150+
151+
command = "add-nat-rule"
152+
153+
result = api_command(module, command)
154+
module.exit_json(**result)
155+
156+
157+
if __name__ == '__main__':
158+
main()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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_nat_rule
31+
short_description: Delete existing object using object name or uid.
32+
description:
33+
- Delete existing object using object name or uid.
34+
- All operations are performed over Web Services API.
35+
version_added: "2.9"
36+
author: "Or Soffer (@chkp-orso)"
37+
options:
38+
rule_number:
39+
description:
40+
- Rule number.
41+
type: str
42+
package:
43+
description:
44+
- Name of the package.
45+
type: str
46+
details_level:
47+
description:
48+
- 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
49+
representation of the object.
50+
type: str
51+
choices: ['uid', 'standard', 'full']
52+
extends_documentation_fragment: check_point.mgmt.checkpoint_commands
53+
"""
54+
55+
EXAMPLES = """
56+
- name: delete-nat-rule
57+
cp_mgmt_delete_nat_rule:
58+
package: standard
59+
state: absent
60+
"""
61+
62+
RETURN = """
63+
cp_mgmt_delete_nat_rule:
64+
description: The checkpoint delete-nat-rule output.
65+
returned: always.
66+
type: dict
67+
"""
68+
69+
from ansible.module_utils.basic import AnsibleModule
70+
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_commands, api_command
71+
72+
73+
def main():
74+
argument_spec = dict(
75+
rule_number=dict(type='str'),
76+
package=dict(type='str'),
77+
details_level=dict(type='str', choices=['uid', 'standard', 'full'])
78+
)
79+
argument_spec.update(checkpoint_argument_spec_for_commands)
80+
81+
module = AnsibleModule(argument_spec=argument_spec)
82+
83+
command = "delete-nat-rule"
84+
85+
result = api_command(module, command)
86+
module.exit_json(**result)
87+
88+
89+
if __name__ == '__main__':
90+
main()

0 commit comments

Comments
 (0)