| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage Check Point 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 = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_service_group_facts |
| 33 |
short_description: Get service-group objects facts on Check Point over Web Services API |
| 34 |
description: |
| 35 |
- Get service-group objects facts on Check Point devices. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- This module handles both operations, get a specific object and get several objects, |
| 38 |
For getting a specific object use the parameter 'name'. |
| 39 |
- Available from R80 management version. |
| 40 |
version_added: "1.0.0" |
| 41 |
author: "Or Soffer (@chkp-orso)" |
| 42 |
options: |
| 43 |
name: |
| 44 |
description: |
| 45 |
- Object name. |
| 46 |
This parameter is relevant only for getting a specific object. |
| 47 |
type: str |
| 48 |
show_as_ranges: |
| 49 |
description: |
| 50 |
- When true, the service group's matched content is displayed as ranges of port numbers rather than service objects.<br />Objects that are not |
| 51 |
represented using port numbers are presented as objects.<br />The 'members' parameter is omitted from the response and instead the 'ranges' parameter |
| 52 |
is displayed. |
| 53 |
- Available from R80.20 management version. |
| 54 |
type: bool |
| 55 |
details_level: |
| 56 |
description: |
| 57 |
- 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 |
| 58 |
representation of the object. |
| 59 |
type: str |
| 60 |
choices: ['uid', 'standard', 'full'] |
| 61 |
filter: |
| 62 |
description: |
| 63 |
- Search expression to filter objects by. The provided text should be exactly the same as it would be given in SmartConsole Object Explorer. The |
| 64 |
logical operators in the expression ('AND', 'OR') should be provided in capital letters. The search involves both a IP search and a textual search in |
| 65 |
name, comment, tags etc. |
| 66 |
- Available from R81 JHF management version. |
| 67 |
type: str |
| 68 |
version_added: "6.4.0" |
| 69 |
limit: |
| 70 |
description: |
| 71 |
- No more than that many results will be returned. |
| 72 |
This parameter is relevant only for getting few objects. |
| 73 |
type: int |
| 74 |
offset: |
| 75 |
description: |
| 76 |
- Skip that many results before beginning to return them. |
| 77 |
This parameter is relevant only for getting few objects. |
| 78 |
type: int |
| 79 |
order: |
| 80 |
description: |
| 81 |
- Sorts results by the given field. By default the results are sorted in the ascending order by name. |
| 82 |
This parameter is relevant only for getting few objects. |
| 83 |
type: list |
| 84 |
elements: dict |
| 85 |
suboptions: |
| 86 |
ASC: |
| 87 |
description: |
| 88 |
- Sorts results by the given field in ascending order. |
| 89 |
type: str |
| 90 |
choices: ['name'] |
| 91 |
DESC: |
| 92 |
description: |
| 93 |
- Sorts results by the given field in descending order. |
| 94 |
type: str |
| 95 |
choices: ['name'] |
| 96 |
dereference_group_members: |
| 97 |
description: |
| 98 |
- Indicates whether to dereference "members" field by details level for every object in reply. |
| 99 |
- Available from R80.10 management version. |
| 100 |
type: bool |
| 101 |
show_membership: |
| 102 |
description: |
| 103 |
- Indicates whether to calculate and show "groups" field for every object in reply. |
| 104 |
- Available from R80.10 management version. |
| 105 |
type: bool |
| 106 |
domains_to_process: |
| 107 |
description: |
| 108 |
- 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 |
| 109 |
with ignore-warnings true. Valid values are, CURRENT_DOMAIN, ALL_DOMAINS_ON_THIS_SERVER. |
| 110 |
- Available from R81 management version. |
| 111 |
type: list |
| 112 |
elements: str |
| 113 |
version_added: "6.4.0" |
| 114 |
extends_documentation_fragment: check_point.mgmt.checkpoint_facts |
| 115 |
""" |
| 116 |
|
| 117 |
EXAMPLES = """ |
| 118 |
- name: show-service-group |
| 119 |
cp_mgmt_service_group_facts: |
| 120 |
name: New Service Group 1 |
| 121 |
|
| 122 |
- name: show-service-groups |
| 123 |
cp_mgmt_service_group_facts: |
| 124 |
details_level: standard |
| 125 |
limit: 50 |
| 126 |
offset: 0 |
| 127 |
""" |
| 128 |
|
| 129 |
RETURN = """ |
| 130 |
ansible_facts: |
| 131 |
description: The checkpoint object facts. |
| 132 |
returned: always. |
| 133 |
type: dict |
| 134 |
""" |
| 135 |
|
| 136 |
from ansible.module_utils.basic import AnsibleModule |
| 137 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 138 |
checkpoint_argument_spec_for_facts, |
| 139 |
api_call_facts, |
| 140 |
) |
| 141 |
|
| 142 |
|
| 143 |
def main(): |
| 144 |
argument_spec = dict( |
| 145 |
name=dict(type="str"), |
| 146 |
show_as_ranges=dict(type="bool"), |
| 147 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 148 |
filter=dict(type='str'), |
| 149 |
limit=dict(type="int"), |
| 150 |
offset=dict(type="int"), |
| 151 |
order=dict( |
| 152 |
type="list", |
| 153 |
elements="dict", |
| 154 |
options=dict( |
| 155 |
ASC=dict(type="str", choices=["name"]), |
| 156 |
DESC=dict(type="str", choices=["name"]), |
| 157 |
), |
| 158 |
), |
| 159 |
dereference_group_members=dict(type="bool"), |
| 160 |
show_membership=dict(type="bool"), |
| 161 |
domains_to_process=dict(type='list', elements="str") |
| 162 |
) |
| 163 |
argument_spec.update(checkpoint_argument_spec_for_facts) |
| 164 |
|
| 165 |
module = AnsibleModule( |
| 166 |
argument_spec=argument_spec, supports_check_mode=True |
| 167 |
) |
| 168 |
|
| 169 |
api_call_object = "service-group" |
| 170 |
api_call_object_plural_version = "service-groups" |
| 171 |
|
| 172 |
result = api_call_facts( |
| 173 |
module, api_call_object, api_call_object_plural_version |
| 174 |
) |
| 175 |
module.exit_json(ansible_facts=result) |
| 176 |
|
| 177 |
|
| 178 |
if __name__ == "__main__": |
| 179 |
main() |