Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_system_mail.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_system_mail
15 short_description: Alert emails.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 system_mail:
22 description: The top level parameters set.
23 required: false
24 type: dict
25 suboptions:
26 auth:
27 type: str
28 description:
29 - Enable authentication.
30 - disable - Disable authentication.
31 - enable - Enable authentication.
32 choices: ['disable', 'enable']
33 id:
34 type: str
35 description: Mail Service ID.
36 required: true
37 passwd:
38 type: raw
39 description: (list) SMTP account password.
40 port:
41 type: int
42 description: SMTP server port.
43 secure_option:
44 aliases: ['secure-option']
45 type: str
46 description:
47 - Communication secure option.
48 - default - Try STARTTLS, proceed as plain text communication otherwise.
49 - none - Communication will be in plain text format.
50 - smtps - Communication will be protected by SMTPS.
51 - starttls - Communication will be protected by STARTTLS.
52 choices: ['default', 'none', 'smtps', 'starttls']
53 server:
54 type: str
55 description: SMTP server.
56 user:
57 type: str
58 description: SMTP account username.
59 auth_type:
60 aliases: ['auth-type']
61 type: str
62 description:
63 - SMTP authentication type.
64 - psk - Use username and password to authenticate.
65 - certificate - Use local certificate to authenticate.
66 choices: ['psk', 'certificate']
67 local_cert:
68 aliases: ['local-cert']
69 type: str
70 description: SMTP local certificate.
71 from:
72 type: str
73 description: Username for MAIL FROM.
74 ssl_protocol:
75 aliases: ['ssl-protocol']
76 type: str
77 description:
78 - set the lowest SSL protocol version for connection to mail server.
79 - follow-global-ssl-protocol - Follow system.
80 - sslv3 - set SSLv3 as the lowest version.
81 - tlsv1.
82 - tlsv1.
83 - tlsv1.
84 - tlsv1.
85 choices: ['follow-global-ssl-protocol', 'sslv3', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2',
86 'tlsv1.3']
87 '''
88
89 EXAMPLES = '''
90 - name: Example playbook
91 hosts: fortimanagers
92 gather_facts: false
93 connection: httpapi
94 vars:
95 ansible_httpapi_use_ssl: true
96 ansible_httpapi_validate_certs: false
97 ansible_httpapi_port: 443
98 tasks:
99 - name: Alert emails.
100 fortinet.fortimanager.fmgr_system_mail:
101 bypass_validation: false
102 state: present
103 system_mail:
104 auth: enable
105 id: 1
106 passwd: fortinet
107 port: 1
108 secure_option: none # <value in [default, none, smtps, ...]>
109 server: ALL
110 user: ansible
111
112 - name: Gathering fortimanager facts
113 hosts: fortimanagers
114 gather_facts: false
115 connection: httpapi
116 vars:
117 ansible_httpapi_use_ssl: true
118 ansible_httpapi_validate_certs: false
119 ansible_httpapi_port: 443
120 tasks:
121 - name: Retrieve all the alert emails
122 fortinet.fortimanager.fmgr_fact:
123 facts:
124 selector: "system_mail"
125 params:
126 mail: "your_value"
127 '''
128
129 RETURN = '''
130 meta:
131 description: The result of the request.
132 type: dict
133 returned: always
134 contains:
135 request_url:
136 description: The full url requested.
137 returned: always
138 type: str
139 sample: /sys/login/user
140 response_code:
141 description: The status of api request.
142 returned: always
143 type: int
144 sample: 0
145 response_data:
146 description: The api response.
147 type: list
148 returned: always
149 response_message:
150 description: The descriptive message of the api response.
151 type: str
152 returned: always
153 sample: OK.
154 system_information:
155 description: The information of the target system.
156 type: dict
157 returned: always
158 rc:
159 description: The status the request.
160 type: int
161 returned: always
162 sample: 0
163 version_check_warning:
164 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
165 type: list
166 returned: complex
167 '''
168 from ansible.module_utils.basic import AnsibleModule
169 from ansible.module_utils.connection import Connection
170 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
171 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
172
173
174 def main():
175 urls_list = [
176 '/cli/global/system/mail'
177 ]
178 module_arg_spec = {
179 'system_mail': {
180 'type': 'dict', 'v_range': [['6.0.0', '']],
181 'options': {
182 'auth': {'choices': ['disable', 'enable'], 'type': 'str'},
183 'id': {'required': True, 'type': 'str'},
184 'passwd': {'no_log': True, 'type': 'raw'},
185 'port': {'type': 'int'},
186 'secure-option': {'choices': ['default', 'none', 'smtps', 'starttls'], 'type': 'str'},
187 'server': {'type': 'str'},
188 'user': {'type': 'str'},
189 'auth-type': {'v_range': [['6.4.6', '']], 'choices': ['psk', 'certificate'], 'type': 'str'},
190 'local-cert': {'v_range': [['6.4.6', '']], 'type': 'str'},
191 'from': {'v_range': [['7.0.7', '7.0.16'], ['7.2.2', '']], 'type': 'str'},
192 'ssl-protocol': {
193 'v_range': [['7.4.4', '7.4.10'], ['7.6.2', '']],
194 'choices': ['follow-global-ssl-protocol', 'sslv3', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', 'tlsv1.3'],
195 'type': 'str'
196 }
197 }
198 }
199 }
200
201 module_option_spec = get_module_arg_spec('full crud')
202 module_arg_spec.update(module_option_spec)
203 check_galaxy_version(module_arg_spec)
204 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_mail'),
205 supports_check_mode=True)
206 if not module._socket_path:
207 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
208 connection = Connection(module._socket_path)
209 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
210 'id', 'data', module, connection)
211 fmgr.process_crud()
212 module.exit_json(meta=module.params)
213
214
215 if __name__ == '__main__':
216 main()