Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_pkg_firewall_localinpolicy.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_localinpolicy
15 short_description: Configure user defined IPv4 local-in 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_localinpolicy:
33 description: The top level parameters set.
34 required: false
35 type: dict
36 suboptions:
37 action:
38 type: str
39 description: Action performed on traffic matching the policy
40 choices: ['deny', 'accept']
41 dstaddr:
42 type: raw
43 description: (list or str) Destination address object from available options.
44 ha_mgmt_intf_only:
45 aliases: ['ha-mgmt-intf-only']
46 type: str
47 description: Enable/disable dedicating the HA management interface only for local-in policy.
48 choices: ['disable', 'enable']
49 intf:
50 type: raw
51 description: Incoming interface name from available options.
52 policyid:
53 type: int
54 description: User defined local in policy ID.
55 required: true
56 schedule:
57 type: str
58 description: Schedule object from available options.
59 service:
60 type: raw
61 description: (list or str) Service object from available options.
62 srcaddr:
63 type: raw
64 description: (list or str) Source address object from available options.
65 status:
66 type: str
67 description: Enable/disable this local-in policy.
68 choices: ['disable', 'enable']
69 comments:
70 type: str
71 description: Comment.
72 uuid:
73 type: str
74 description: Universally Unique Identifier
75 dstaddr_negate:
76 aliases: ['dstaddr-negate']
77 type: str
78 description: When enabled dstaddr specifies what the destination address must NOT be.
79 choices: ['disable', 'enable']
80 service_negate:
81 aliases: ['service-negate']
82 type: str
83 description: When enabled service specifies what the service must NOT be.
84 choices: ['disable', 'enable']
85 srcaddr_negate:
86 aliases: ['srcaddr-negate']
87 type: str
88 description: When enabled srcaddr specifies what the source address must NOT be.
89 choices: ['disable', 'enable']
90 virtual_patch:
91 aliases: ['virtual-patch']
92 type: str
93 description: Enable/disable virtual patching.
94 choices: ['disable', 'enable']
95 internet_service_src:
96 aliases: ['internet-service-src']
97 type: str
98 description: Enable/disable use of Internet Services in source for this local-in policy.
99 choices: ['disable', 'enable']
100 internet_service_src_custom:
101 aliases: ['internet-service-src-custom']
102 type: raw
103 description: (list) Custom Internet Service source name.
104 internet_service_src_custom_group:
105 aliases: ['internet-service-src-custom-group']
106 type: raw
107 description: (list) Custom Internet Service source group name.
108 internet_service_src_group:
109 aliases: ['internet-service-src-group']
110 type: raw
111 description: (list) Internet Service source group name.
112 internet_service_src_name:
113 aliases: ['internet-service-src-name']
114 type: raw
115 description: (list) Internet Service source name.
116 internet_service_src_negate:
117 aliases: ['internet-service-src-negate']
118 type: str
119 description: When enabled internet-service-src specifies what the service must NOT be.
120 choices: ['disable', 'enable']
121 logtraffic:
122 type: str
123 description: Enable/disable local-in traffic logging.
124 choices: ['disable', 'enable']
125 internet_service_src_fortiguard:
126 aliases: ['internet-service-src-fortiguard']
127 type: raw
128 description: (list) FortiGuard Internet Service source name.
129 '''
130
131 EXAMPLES = '''
132 - name: Example playbook
133 hosts: fortimanagers
134 gather_facts: false
135 connection: httpapi
136 vars:
137 ansible_httpapi_use_ssl: true
138 ansible_httpapi_validate_certs: false
139 ansible_httpapi_port: 443
140 tasks:
141 - name: Configure user defined IPv4 local-in policies.
142 fortinet.fortimanager.fmgr_pkg_firewall_localinpolicy:
143 bypass_validation: false
144 adom: ansible
145 pkg: ansible # package name
146 state: present
147 pkg_firewall_localinpolicy:
148 action: deny # <value in [deny, accept]>
149 dstaddr: all
150 intf: any
151 policyid: 1
152 schedule: always
153 service: ALL
154 srcaddr: all
155 status: disable
156
157 - name: Gathering fortimanager facts
158 hosts: fortimanagers
159 gather_facts: false
160 connection: httpapi
161 vars:
162 ansible_httpapi_use_ssl: true
163 ansible_httpapi_validate_certs: false
164 ansible_httpapi_port: 443
165 tasks:
166 - name: Retrieve all the user defined IPv4 local-in policies
167 fortinet.fortimanager.fmgr_fact:
168 facts:
169 selector: "pkg_firewall_localinpolicy"
170 params:
171 adom: "ansible"
172 pkg: "ansible" # package name
173 local_in_policy: "your_value"
174 '''
175
176 RETURN = '''
177 meta:
178 description: The result of the request.
179 type: dict
180 returned: always
181 contains:
182 request_url:
183 description: The full url requested.
184 returned: always
185 type: str
186 sample: /sys/login/user
187 response_code:
188 description: The status of api request.
189 returned: always
190 type: int
191 sample: 0
192 response_data:
193 description: The api response.
194 type: list
195 returned: always
196 response_message:
197 description: The descriptive message of the api response.
198 type: str
199 returned: always
200 sample: OK.
201 system_information:
202 description: The information of the target system.
203 type: dict
204 returned: always
205 rc:
206 description: The status the request.
207 type: int
208 returned: always
209 sample: 0
210 version_check_warning:
211 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
212 type: list
213 returned: complex
214 '''
215 from ansible.module_utils.basic import AnsibleModule
216 from ansible.module_utils.connection import Connection
217 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
218 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
219
220
221 def main():
222 urls_list = [
223 '/pm/config/adom/{adom}/pkg/{pkg}/firewall/local-in-policy'
224 ]
225 module_arg_spec = {
226 'adom': {'required': True, 'type': 'str'},
227 'pkg': {'required': True, 'type': 'str'},
228 'revision_note': {'type': 'str'},
229 'pkg_firewall_localinpolicy': {
230 'type': 'dict', 'v_range': [['6.0.0', '']],
231 'options': {
232 'action': {'choices': ['deny', 'accept'], 'type': 'str'},
233 'dstaddr': {'type': 'raw'},
234 'ha-mgmt-intf-only': {'choices': ['disable', 'enable'], 'type': 'str'},
235 'intf': {'type': 'raw'},
236 'policyid': {'required': True, 'type': 'int'},
237 'schedule': {'type': 'str'},
238 'service': {'type': 'raw'},
239 'srcaddr': {'type': 'raw'},
240 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
241 'comments': {'v_range': [['6.2.0', '']], 'type': 'str'},
242 'uuid': {'v_range': [['6.2.1', '']], 'type': 'str'},
243 'dstaddr-negate': {'v_range': [['7.0.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
244 'service-negate': {'v_range': [['7.0.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
245 'srcaddr-negate': {'v_range': [['7.0.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
246 'virtual-patch': {'v_range': [['7.2.6', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
247 'internet-service-src': {'v_range': [['7.4.3', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
248 'internet-service-src-custom': {'v_range': [['7.4.3', '']], 'type': 'raw'},
249 'internet-service-src-custom-group': {'v_range': [['7.4.3', '']], 'type': 'raw'},
250 'internet-service-src-group': {'v_range': [['7.4.3', '']], 'type': 'raw'},
251 'internet-service-src-name': {'v_range': [['7.4.3', '']], 'type': 'raw'},
252 'internet-service-src-negate': {'v_range': [['7.4.3', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
253 'logtraffic': {'v_range': [['7.6.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
254 'internet-service-src-fortiguard': {'v_range': [['7.6.4', '']], 'type': 'raw'}
255 }
256 }
257 }
258
259 module_option_spec = get_module_arg_spec('full crud')
260 module_arg_spec.update(module_option_spec)
261 check_galaxy_version(module_arg_spec)
262 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'pkg_firewall_localinpolicy'),
263 supports_check_mode=True)
264 if not module._socket_path:
265 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
266 connection = Connection(module._socket_path)
267 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
268 'policyid', 'data', module, connection)
269 fmgr.process_crud()
270 module.exit_json(meta=module.params)
271
272
273 if __name__ == '__main__':
274 main()