Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_pkg_firewall_centralsnatmap.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_pkg_firewall_centralsnatmap
15 short_description: Configure central SNAT policies.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 pkg:
29 description: The parameter (pkg) in requested url.
30 type: str
31 required: true
32 pkg_firewall_centralsnatmap:
33 description: The top level parameters set.
34 required: false
35 type: dict
36 suboptions:
37 dst_addr:
38 aliases: ['dst-addr']
39 type: raw
40 description: (list or str) Destination address name from available addresses.
41 dstintf:
42 type: raw
43 description: (list or str) Destination interface name from available interfaces.
44 nat:
45 type: str
46 description: Enable/disable source NAT.
47 choices: ['disable', 'enable']
48 nat_ippool:
49 aliases: ['nat-ippool']
50 type: raw
51 description: (list or str) Name of the IP pools to be used to translate addresses from available IP Pools.
52 nat_port:
53 aliases: ['nat-port']
54 type: str
55 description: Translated port or port range
56 orig_addr:
57 aliases: ['orig-addr']
58 type: raw
59 description: (list or str) Original address.
60 orig_port:
61 aliases: ['orig-port']
62 type: raw
63 description: (int or str) Original TCP port
64 policyid:
65 type: int
66 description: Policy ID.
67 required: true
68 protocol:
69 type: int
70 description: Integer value for the protocol type
71 srcintf:
72 type: raw
73 description: (list or str) Source interface name from available interfaces.
74 status:
75 type: str
76 description: Enable/disable the active status of this policy.
77 choices: ['disable', 'enable']
78 comments:
79 type: str
80 description: Comment.
81 dst_addr6:
82 aliases: ['dst-addr6']
83 type: raw
84 description: (list or str) IPv6 Destination address.
85 nat_ippool6:
86 aliases: ['nat-ippool6']
87 type: raw
88 description: (list or str) IPv6 pools to be used for source NAT.
89 orig_addr6:
90 aliases: ['orig-addr6']
91 type: raw
92 description: (list or str) IPv6 Original address.
93 type:
94 type: str
95 description: IPv4/IPv6 source NAT.
96 choices: ['ipv4', 'ipv6']
97 uuid:
98 type: str
99 description: Universally Unique Identifier
100 nat46:
101 type: str
102 description: Enable/disable NAT46.
103 choices: ['disable', 'enable']
104 nat64:
105 type: str
106 description: Enable/disable NAT64.
107 choices: ['disable', 'enable']
108 dst_port:
109 aliases: ['dst-port']
110 type: str
111 description: Destination port or port range
112 port_preserve:
113 aliases: ['port-preserve']
114 type: str
115 description: Enable/disable preservation of the original source port from source NAT if it has not been used.
116 choices: ['disable', 'enable']
117 port_random:
118 aliases: ['port-random']
119 type: str
120 description: Enable/disable random source port selection for source NAT.
121 choices: ['disable', 'enable']
122 action:
123 type: str
124 description: Central SNAT action.
125 choices: ['bypass', 'masquerade', 'ippool']
126 ipv6:
127 type: str
128 description: Enable/disable IPv6.
129 choices: ['disable', 'enable']
130 src_addr:
131 aliases: ['src-addr']
132 type: raw
133 description: (list) Original source address.
134 src_addr6:
135 aliases: ['src-addr6']
136 type: raw
137 description: (list) Original IPV6 source address.
138 '''
139
140 EXAMPLES = '''
141 - name: Example playbook
142 hosts: fortimanagers
143 gather_facts: false
144 connection: httpapi
145 vars:
146 ansible_httpapi_use_ssl: true
147 ansible_httpapi_validate_certs: false
148 ansible_httpapi_port: 443
149 tasks:
150 - name: Configure central SNAT policies.
151 fortinet.fortimanager.fmgr_pkg_firewall_centralsnatmap:
152 bypass_validation: false
153 adom: ansible
154 pkg: ansible # package name
155 state: present
156 pkg_firewall_centralsnatmap:
157 dst_addr: "ansible-test1"
158 nat: enable
159 orig_addr: "ansible-test1"
160 policyid: 2
161 status: disable
162
163 - name: Gathering fortimanager facts
164 hosts: fortimanagers
165 gather_facts: false
166 connection: httpapi
167 vars:
168 ansible_httpapi_use_ssl: true
169 ansible_httpapi_validate_certs: false
170 ansible_httpapi_port: 443
171 tasks:
172 - name: Retrieve all the central SNAT policies
173 fortinet.fortimanager.fmgr_fact:
174 facts:
175 selector: "pkg_firewall_centralsnatmap"
176 params:
177 adom: "ansible"
178 pkg: "ansible" # package name
179 central_snat_map: "your_value"
180 '''
181
182 RETURN = '''
183 meta:
184 description: The result of the request.
185 type: dict
186 returned: always
187 contains:
188 request_url:
189 description: The full url requested.
190 returned: always
191 type: str
192 sample: /sys/login/user
193 response_code:
194 description: The status of api request.
195 returned: always
196 type: int
197 sample: 0
198 response_data:
199 description: The api response.
200 type: list
201 returned: always
202 response_message:
203 description: The descriptive message of the api response.
204 type: str
205 returned: always
206 sample: OK.
207 system_information:
208 description: The information of the target system.
209 type: dict
210 returned: always
211 rc:
212 description: The status the request.
213 type: int
214 returned: always
215 sample: 0
216 version_check_warning:
217 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
218 type: list
219 returned: complex
220 '''
221 from ansible.module_utils.basic import AnsibleModule
222 from ansible.module_utils.connection import Connection
223 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
224 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
225
226
227 def main():
228 urls_list = [
229 '/pm/config/adom/{adom}/pkg/{pkg}/firewall/central-snat-map'
230 ]
231 module_arg_spec = {
232 'adom': {'required': True, 'type': 'str'},
233 'pkg': {'required': True, 'type': 'str'},
234 'revision_note': {'type': 'str'},
235 'pkg_firewall_centralsnatmap': {
236 'type': 'dict', 'v_range': [['6.0.0', '']],
237 'options': {
238 'dst-addr': {'type': 'raw'},
239 'dstintf': {'type': 'raw'},
240 'nat': {'choices': ['disable', 'enable'], 'type': 'str'},
241 'nat-ippool': {'type': 'raw'},
242 'nat-port': {'type': 'str'},
243 'orig-addr': {'type': 'raw'},
244 'orig-port': {'type': 'raw'},
245 'policyid': {'required': True, 'type': 'int'},
246 'protocol': {'type': 'int'},
247 'srcintf': {'type': 'raw'},
248 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
249 'comments': {'v_range': [['6.2.0', '']], 'type': 'str'},
250 'dst-addr6': {'v_range': [['6.4.0', '']], 'type': 'raw'},
251 'nat-ippool6': {'v_range': [['6.4.0', '']], 'type': 'raw'},
252 'orig-addr6': {'v_range': [['6.4.0', '']], 'type': 'raw'},
253 'type': {'v_range': [['6.4.0', '']], 'choices': ['ipv4', 'ipv6'], 'type': 'str'},
254 'uuid': {'v_range': [['6.4.0', '']], 'type': 'str'},
255 'nat46': {'v_range': [['7.0.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
256 'nat64': {'v_range': [['7.0.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
257 'dst-port': {'v_range': [['7.2.6', '']], 'type': 'str'},
258 'port-preserve': {'v_range': [['7.4.3', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
259 'port-random': {'v_range': [['7.6.2', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
260 'action': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['bypass', 'masquerade', 'ippool'], 'type': 'str'},
261 'ipv6': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
262 'src-addr': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'raw'},
263 'src-addr6': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'raw'}
264 }
265 }
266 }
267
268 module_option_spec = get_module_arg_spec('full crud')
269 module_arg_spec.update(module_option_spec)
270 check_galaxy_version(module_arg_spec)
271 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'pkg_firewall_centralsnatmap'),
272 supports_check_mode=True)
273 if not module._socket_path:
274 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
275 connection = Connection(module._socket_path)
276 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
277 'policyid', 'data', module, connection)
278 fmgr.process_crud()
279 module.exit_json(meta=module.params)
280
281
282 if __name__ == '__main__':
283 main()