| 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_user_template |
| 31 |
short_description: Manages user-template objects on Checkpoint over Web Services API |
| 32 |
description: |
| 33 |
- Manages user-template objects on Checkpoint devices including creating, updating and removing objects. |
| 34 |
- All operations are performed over Web Services API. |
| 35 |
- Available from R80.40 JHF management version. |
| 36 |
version_added: "6.4.0" |
| 37 |
author: "Dor Berenstein (@chkp-dorbe)" |
| 38 |
options: |
| 39 |
name: |
| 40 |
description: |
| 41 |
- Object name. |
| 42 |
type: str |
| 43 |
required: True |
| 44 |
expiration_by_global_properties: |
| 45 |
description: |
| 46 |
- Expiration date according to global properties. |
| 47 |
type: bool |
| 48 |
expiration_date: |
| 49 |
description: |
| 50 |
- Expiration date in format, yyyy-MM-dd. |
| 51 |
type: str |
| 52 |
authentication_method: |
| 53 |
description: |
| 54 |
- Authentication method. |
| 55 |
type: str |
| 56 |
choices: ['undefined', 'check point password', 'os password', 'securid', 'radius', 'tacacs'] |
| 57 |
radius_server: |
| 58 |
description: |
| 59 |
- RADIUS server object identified by the name or UID. Must be set when "authentication-method" was selected to be "RADIUS". |
| 60 |
type: str |
| 61 |
tacacs_server: |
| 62 |
description: |
| 63 |
- TACACS server object identified by the name or UID. Must be set when "authentication-method" was selected to be "TACACS". |
| 64 |
type: str |
| 65 |
connect_on_days: |
| 66 |
description: |
| 67 |
- Days users allow to connect. |
| 68 |
type: list |
| 69 |
elements: str |
| 70 |
connect_daily: |
| 71 |
description: |
| 72 |
- Connect every day. |
| 73 |
type: bool |
| 74 |
from_hour: |
| 75 |
description: |
| 76 |
- Allow users connect from hour. |
| 77 |
type: str |
| 78 |
to_hour: |
| 79 |
description: |
| 80 |
- Allow users connect until hour. |
| 81 |
type: str |
| 82 |
allowed_locations: |
| 83 |
description: |
| 84 |
- User allowed locations. |
| 85 |
type: dict |
| 86 |
suboptions: |
| 87 |
destinations: |
| 88 |
description: |
| 89 |
- Collection of allowed destination locations name or uid. |
| 90 |
type: list |
| 91 |
elements: str |
| 92 |
sources: |
| 93 |
description: |
| 94 |
- Collection of allowed source locations name or uid. |
| 95 |
type: list |
| 96 |
elements: str |
| 97 |
encryption: |
| 98 |
description: |
| 99 |
- User encryption. |
| 100 |
type: dict |
| 101 |
suboptions: |
| 102 |
ike: |
| 103 |
description: |
| 104 |
- Enable IKE encryption for users. |
| 105 |
type: bool |
| 106 |
public_key: |
| 107 |
description: |
| 108 |
- Enable IKE public key. |
| 109 |
type: bool |
| 110 |
tags: |
| 111 |
description: |
| 112 |
- Collection of tag identifiers. |
| 113 |
type: list |
| 114 |
elements: str |
| 115 |
color: |
| 116 |
description: |
| 117 |
- Color of the object. Should be one of existing colors. |
| 118 |
type: str |
| 119 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 120 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 121 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 122 |
comments: |
| 123 |
description: |
| 124 |
- Comments string. |
| 125 |
type: str |
| 126 |
details_level: |
| 127 |
description: |
| 128 |
- 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 |
| 129 |
representation of the object. |
| 130 |
type: str |
| 131 |
choices: ['uid', 'standard', 'full'] |
| 132 |
ignore_warnings: |
| 133 |
description: |
| 134 |
- Apply changes ignoring warnings. |
| 135 |
type: bool |
| 136 |
groups: |
| 137 |
description: |
| 138 |
- Collection of group identifiers. |
| 139 |
type: list |
| 140 |
elements: str |
| 141 |
ignore_errors: |
| 142 |
description: |
| 143 |
- 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. |
| 144 |
type: bool |
| 145 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 146 |
""" |
| 147 |
|
| 148 |
EXAMPLES = """ |
| 149 |
- name: add-user-template |
| 150 |
cp_mgmt_user_template: |
| 151 |
expiration_by_global_properties: 'False' |
| 152 |
expiration_date: '2030-05-30' |
| 153 |
name: myusertemplate |
| 154 |
state: present |
| 155 |
|
| 156 |
- name: set-user-template |
| 157 |
cp_mgmt_user_template: |
| 158 |
expiration_by_global_properties: 'True' |
| 159 |
name: myusertemplate |
| 160 |
state: present |
| 161 |
|
| 162 |
- name: delete-user-template |
| 163 |
cp_mgmt_user_template: |
| 164 |
name: myusertemplate |
| 165 |
state: absent |
| 166 |
""" |
| 167 |
|
| 168 |
RETURN = """ |
| 169 |
cp_mgmt_user_template: |
| 170 |
description: The checkpoint object created or updated. |
| 171 |
returned: always, except when deleting the object. |
| 172 |
type: dict |
| 173 |
""" |
| 174 |
|
| 175 |
from ansible.module_utils.basic import AnsibleModule |
| 176 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call |
| 177 |
|
| 178 |
|
| 179 |
def main(): |
| 180 |
argument_spec = dict( |
| 181 |
name=dict(type='str', required=True), |
| 182 |
expiration_by_global_properties=dict(type='bool'), |
| 183 |
expiration_date=dict(type='str'), |
| 184 |
authentication_method=dict(type='str', choices=['undefined', 'check point password', 'os password', 'securid', 'radius', 'tacacs']), |
| 185 |
radius_server=dict(type='str'), |
| 186 |
tacacs_server=dict(type='str'), |
| 187 |
connect_on_days=dict(type='list', elements="str"), |
| 188 |
connect_daily=dict(type='bool'), |
| 189 |
from_hour=dict(type='str'), |
| 190 |
to_hour=dict(type='str'), |
| 191 |
allowed_locations=dict(type='dict', options=dict( |
| 192 |
destinations=dict(type='list', elements="str"), |
| 193 |
sources=dict(type='list', elements="str") |
| 194 |
)), |
| 195 |
encryption=dict(type='dict', options=dict( |
| 196 |
ike=dict(type='bool'), |
| 197 |
public_key=dict(type='bool') |
| 198 |
)), |
| 199 |
tags=dict(type='list', elements="str"), |
| 200 |
color=dict(type='str', choices=['aquamarine', |
| 201 |
'black', |
| 202 |
'blue', |
| 203 |
'crete blue', |
| 204 |
'burlywood', |
| 205 |
'cyan', |
| 206 |
'dark green', |
| 207 |
'khaki', |
| 208 |
'orchid', |
| 209 |
'dark orange', |
| 210 |
'dark sea green', |
| 211 |
'pink', |
| 212 |
'turquoise', |
| 213 |
'dark blue', |
| 214 |
'firebrick', |
| 215 |
'brown', |
| 216 |
'forest green', |
| 217 |
'gold', |
| 218 |
'dark gold', |
| 219 |
'gray', |
| 220 |
'dark gray', |
| 221 |
'light green', |
| 222 |
'lemon chiffon', |
| 223 |
'coral', |
| 224 |
'sea green', |
| 225 |
'sky blue', |
| 226 |
'magenta', |
| 227 |
'purple', |
| 228 |
'slate blue', |
| 229 |
'violet red', |
| 230 |
'navy blue', |
| 231 |
'olive', |
| 232 |
'orange', |
| 233 |
'red', |
| 234 |
'sienna', |
| 235 |
'yellow']), |
| 236 |
comments=dict(type='str'), |
| 237 |
details_level=dict(type='str', choices=['uid', 'standard', 'full']), |
| 238 |
ignore_warnings=dict(type='bool'), |
| 239 |
groups=dict(type='list', elements="str"), |
| 240 |
ignore_errors=dict(type='bool') |
| 241 |
) |
| 242 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 243 |
|
| 244 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 245 |
api_call_object = 'user-template' |
| 246 |
|
| 247 |
result = api_call(module, api_call_object) |
| 248 |
module.exit_json(**result) |
| 249 |
|
| 250 |
|
| 251 |
if __name__ == '__main__': |
| 252 |
main() |