Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_securityconsole_install_package.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_securityconsole_install_package
15 short_description: Copy and install a policy package to devices.
16 version_added: "1.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 options:
20 securityconsole_install_package:
21 description: The top level parameters set.
22 required: false
23 type: dict
24 suboptions:
25 adom:
26 type: str
27 description: Source ADOM name.
28 adom_rev_comments:
29 type: str
30 description: If generate_rev flag is set, the comment for the new ADOM revision.
31 adom_rev_name:
32 type: str
33 description: If generate_rev flag is set, the name for the new ADOM revision.
34 dev_rev_comments:
35 type: str
36 description: Comments for the device configuration revision that will be generated during install.
37 flags:
38 type: list
39 elements: str
40 description:
41 - cp_all_objs - Assign all objects during global policy assignment.
42 - preview - Generate preview cache only.
43 - generate_rev - Generate new ADOM revision before install.
44 - copy_assigned_pkg - For global policy assignment - copy assigned package from ADOM to device.
45 - unassign - Remove global policy from ADOM.
46 - ifpolicy_only - Only install interface policies.
47 - no_ifpolicy - Install regular policies only - do not install interface policies.
48 - objs_only - Install object
49 - auto_lock_ws - Automatically lock and unlock workspace when performing security console task.
50 - copy_only - Only copy to device db.
51 choices: ['none', 'cp_all_objs', 'preview', 'generate_rev', 'copy_assigned_pkg',
52 'unassign', 'ifpolicy_only', 'no_ifpolicy', 'objs_only', 'auto_lock_ws',
53 'check_pkg_st', 'copy_only']
54 pkg:
55 type: str
56 description: Source package path and name.
57 scope:
58 type: list
59 elements: dict
60 description: Scope.
61 suboptions:
62 name:
63 type: str
64 description: Name.
65 vdom:
66 type: str
67 description: Vdom.
68 '''
69
70 EXAMPLES = '''
71 - name: Example playbook
72 hosts: fortimanagers
73 gather_facts: false
74 connection: httpapi
75 vars:
76 ansible_httpapi_use_ssl: true
77 ansible_httpapi_validate_certs: false
78 ansible_httpapi_port: 443
79 tasks:
80 - name: Copy and install a policy package to devices.
81 fortinet.fortimanager.fmgr_securityconsole_install_package:
82 bypass_validation: false
83 securityconsole_install_package:
84 adom: ansible
85 adom_rev_comments: ansible-comment
86 adom_rev_name: ansible-test
87 dev_rev_comments: ansible-comment
88 flags:
89 - none
90 - cp_all_objs
91 - preview
92 - generate_rev
93 - copy_assigned_pkg
94 - unassign
95 - ifpolicy_only
96 - no_ifpolicy
97 - objs_only
98 - auto_lock_ws
99 - check_pkg_st
100 - copy_only
101 pkg: ansible
102 scope:
103 - name: Ansible-test
104 vdom: root
105
106 - name: INSTALL PREVIEW - POLICY PACKAGE
107 hosts: fortimanagers
108 gather_facts: false
109 connection: httpapi
110 vars:
111 adom: demo
112 ppkg: ppkg_hubs
113 device: fgt_00_1
114 tasks:
115 - name: Install for policy package [preview mode] {{ ppkg }}
116 fortinet.fortimanager.fmgr_securityconsole_install_package:
117 securityconsole_install_package:
118 adom: "{{ adom }}"
119 flags:
120 - preview
121 pkg: "{{ ppkg }}"
122 scope:
123 - name: "{{ device }}"
124 vdom: root
125 register: r
126 - name: Poll the task of installing policy package
127 fortinet.fortimanager.fmgr_fact:
128 facts:
129 selector: "task_task"
130 params:
131 task: "{{ r.meta.response_data.task }}"
132 register: taskinfo
133 until: taskinfo.meta.response_data.percent == 100
134 retries: 30
135 delay: 5
136 - name: Trigger the preview report generation for policy package {{ ppkg }}
137 fortinet.fortimanager.fmgr_securityconsole_install_preview:
138 securityconsole_install_preview:
139 adom: "{{ adom }}"
140 device: "{{ device }}"
141 flags:
142 - json
143 vdoms: root
144 register: r
145 - name: Poll the task of generating preview report
146 fortinet.fortimanager.fmgr_fact:
147 facts:
148 selector: "task_task"
149 params:
150 task: "{{ r.meta.response_data.task }}"
151 register: taskinfo
152 until: taskinfo.meta.response_data.percent == 100
153 retries: 30
154 delay: 5
155 - name: Get the preview report for policy package {{ ppkg }}
156 fortinet.fortimanager.fmgr_securityconsole_preview_result:
157 securityconsole_preview_result:
158 adom: "{{ adom }}"
159 device: "{{ device }}"
160 register: r
161 - name: Cancel install task for policy package {{ ppkg }}
162 fortinet.fortimanager.fmgr_securityconsole_package_cancel_install:
163 securityconsole_package_cancel_install:
164 adom: "{{ adom }}"
165 - name: Show preview report
166 ansible.builtin.debug:
167 msg: "{{ r }}"
168 '''
169
170 RETURN = '''
171 meta:
172 description: The result of the request.
173 type: dict
174 returned: always
175 contains:
176 request_url:
177 description: The full url requested.
178 returned: always
179 type: str
180 sample: /sys/login/user
181 response_code:
182 description: The status of api request.
183 returned: always
184 type: int
185 sample: 0
186 response_data:
187 description: The api response.
188 type: list
189 returned: always
190 response_message:
191 description: The descriptive message of the api response.
192 type: str
193 returned: always
194 sample: OK.
195 system_information:
196 description: The information of the target system.
197 type: dict
198 returned: always
199 rc:
200 description: The status the request.
201 type: int
202 returned: always
203 sample: 0
204 version_check_warning:
205 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
206 type: list
207 returned: complex
208 '''
209 from ansible.module_utils.basic import AnsibleModule
210 from ansible.module_utils.connection import Connection
211 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
212 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
213
214
215 def main():
216 urls_list = [
217 '/securityconsole/install/package'
218 ]
219 module_arg_spec = {
220 'securityconsole_install_package': {
221 'type': 'dict', 'v_range': [['6.0.0', '']],
222 'options': {
223 'adom': {'type': 'str'},
224 'adom_rev_comments': {'type': 'str'},
225 'adom_rev_name': {'type': 'str'},
226 'dev_rev_comments': {'type': 'str'},
227 'flags': {
228 'type': 'list',
229 'choices': [
230 'none', 'cp_all_objs', 'preview', 'generate_rev', 'copy_assigned_pkg', 'unassign', 'ifpolicy_only', 'no_ifpolicy', 'objs_only',
231 'auto_lock_ws', 'check_pkg_st', 'copy_only'
232 ],
233 'elements': 'str'
234 },
235 'pkg': {'type': 'str'},
236 'scope': {'type': 'list', 'options': {'name': {'type': 'str'}, 'vdom': {'type': 'str'}}, 'elements': 'dict'}
237 }
238 }
239 }
240
241 module_option_spec = get_module_arg_spec('exec')
242 module_arg_spec.update(module_option_spec)
243 check_galaxy_version(module_arg_spec)
244 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'securityconsole_install_package'),
245 supports_check_mode=True)
246 if not module._socket_path:
247 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
248 connection = Connection(module._socket_path)
249 fmgr = NAPIManager('exec', module_arg_spec, urls_list,
250 None, 'data', module, connection)
251 fmgr.process_exec()
252 module.exit_json(meta=module.params)
253
254
255 if __name__ == '__main__':
256 main()