|
| 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() |
0 commit comments