Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_tacacs_server.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # © Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_tacacs_server
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_tacacs_server
17 version_added: 1.1.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 author: Niraimadaiselvam M (@niraimadaiselvamm)
22 short_description: Manage TACACS server and its parameters
23 description:
24 - This module provides configuration management of tacacs server parameters on devices running Enterprise SONiC.
25 options:
26 config:
27 description:
28 - Specifies the tacacs server related configuration.
29 type: dict
30 suboptions:
31 auth_type:
32 description:
33 - Specifies the authentication type of the tacacs server.
34 type: str
35 choices:
36 - pap
37 - chap
38 - mschap
39 - login
40 default: pap
41 key:
42 description:
43 - Specifies the key of the tacacs server.
44 type: str
45 timeout:
46 description:
47 - Specifies the timeout of the tacacs server.
48 type: int
49 default: 5
50 source_interface:
51 description:
52 - Specifies the source interface of the tacacs server.
53 type: str
54 servers:
55 description:
56 - Specifies the servers list of the tacacs server.
57 type: dict
58 suboptions:
59 host:
60 description:
61 - Specifies the host details of the tacacs servers list.
62 type: list
63 elements: dict
64 suboptions:
65 name:
66 description:
67 - Specifies the name of the tacacs server host.
68 type: str
69 auth_type:
70 description:
71 - Specifies the authentication type of the tacacs server host.
72 type: str
73 choices:
74 - pap
75 - chap
76 - mschap
77 - login
78 default: pap
79 key:
80 description:
81 - Specifies the key of the tacacs server host.
82 type: str
83 priority:
84 description:
85 - Specifies the priority of the tacacs server host.
86 type: int
87 default: 1
88 port:
89 description:
90 - Specifies the port of the tacacs server host.
91 type: int
92 default: 49
93 timeout:
94 description:
95 - Specifies the timeout of the tacacs server host.
96 type: int
97 default: 5
98 vrf:
99 description:
100 - Specifies the vrf of the tacacs server host.
101 type: str
102 default: default
103 state:
104 description:
105 - Specifies the operation to be performed on the tacacs server configured on the device.
106 - In case of merged, the input mode configuration will be merged with the existing tacacs server configuration on the device.
107 - In case of deleted the existing tacacs server mode configuration will be removed from the device.
108 - In case of replaced, the existing tacacs server configuration will be replaced with provided configuration.
109 - In case of overridden, the existing tacacs server configuration will be overridden with the provided configuration.
110 default: merged
111 choices: ['merged', 'replaced', 'overridden', 'deleted']
112 type: str
113 """
114
115 EXAMPLES = """
116 # Using "deleted" state
117 #
118 # Before state:
119 # -------------
120 #
121 # do show tacacs-server
122 # ---------------------------------------------------------
123 # TACACS Global Configuration
124 # ---------------------------------------------------------
125 # source-interface : Ethernet12
126 # timeout : 10
127 # auth-type : login
128 # key : login
129 # ------------------------------------------------------------------------------------------------
130 # HOST AUTH-TYPE KEY PORT PRIORITY TIMEOUT VRF
131 # ------------------------------------------------------------------------------------------------
132 # 1.2.3.4 pap ***** 50 2 10 mgmt
133 # localhost pap 49 1 5 default
134 #
135
136 - name: Merge tacacs configurations
137 dellemc.enterprise_sonic.sonic_tacacs_server:
138 config:
139 auth_type: login
140 key: login
141 source_interface: Ethernet 12
142 timeout: 10
143 servers:
144 host:
145 - name: 1.2.3.4
146 state: deleted
147
148 # After state:
149 # ------------
150 #
151 # do show tacacs-server
152 # ---------------------------------------------------------
153 # TACACS Global Configuration
154 # ---------------------------------------------------------
155 # timeout : 5
156 # auth-type : pap
157 # ------------------------------------------------------------------------------------------------
158 # HOST AUTH-TYPE KEY PORT PRIORITY TIMEOUT VRF
159 # ------------------------------------------------------------------------------------------------
160 # localhost pap 49 1 5 default
161
162
163 # Using "deleted" state
164 #
165 # Before state:
166 # -------------
167 #
168 # do show tacacs-server
169 # ---------------------------------------------------------
170 # TACACS Global Configuration
171 # ---------------------------------------------------------
172 # source-interface : Ethernet12
173 # timeout : 10
174 # auth-type : login
175 # key : login
176 # ------------------------------------------------------------------------------------------------
177 # HOST AUTH-TYPE KEY PORT PRIORITY TIMEOUT VRF
178 # ------------------------------------------------------------------------------------------------
179 # 1.2.3.4 pap ***** 50 2 10 mgmt
180 # localhost pap 49 1 5 default
181 #
182
183 - name: Merge tacacs configurations
184 dellemc.enterprise_sonic.sonic_tacacs_server:
185 config:
186 state: deleted
187
188 # After state:
189 # ------------
190 #
191 # do show tacacs-server
192 # ---------------------------------------------------------
193 # TACACS Global Configuration
194 # ---------------------------------------------------------
195 # timeout : 5
196 # auth-type : pap
197
198
199 # Using "merged" state
200 #
201 # Before state:
202 # -------------
203 #
204 # sonic(config)# do show tacacs-server
205 # ---------------------------------------------------------
206 # TACACS Global Configuration
207 # ---------------------------------------------------------
208 #
209 - name: Merge tacacs configurations
210 dellemc.enterprise_sonic.sonic_tacacs_server:
211 config:
212 auth_type: pap
213 key: pap
214 source_interface: Ethernet 12
215 timeout: 10
216 servers:
217 host:
218 - name: 1.2.3.4
219 auth_type: pap
220 key: 1234
221 state: merged
222
223 # After state:
224 # ------------
225 #
226 # sonic(config)# do show tacacs-server
227 # ---------------------------------------------------------
228 # TACACS Global Configuration
229 # ---------------------------------------------------------
230 # source-interface : Ethernet12
231 # timeout : 10
232 # auth-type : pap
233 # key : pap
234 # ------------------------------------------------------------------------------------------------
235 # HOST AUTH-TYPE KEY PORT PRIORITY TIMEOUT VRF
236 # ------------------------------------------------------------------------------------------------
237 # 1.2.3.4 pap 1234 49 1 5 default
238 #
239 # Using "replaced" state
240 #
241 # Before state:
242 # -------------
243 #
244 # sonic(config)# do show tacacs-server
245 # ---------------------------------------------------------
246 # TACACS Global Configuration
247 # ---------------------------------------------------------
248 # source-interface : Ethernet12
249 # timeout : 10
250 # auth-type : pap
251 # key configured : Yes
252 # --------------------------------------------------------------------------------------
253 # HOST AUTH-TYPE KEY-CONFIG PORT PRIORITY TIMEOUT VRF
254 # --------------------------------------------------------------------------------------
255 # 1.2.3.4 pap No 49 1 5 default
256 #
257 - name: Replace tacacs configurations
258 sonic_tacacs_server:
259 config:
260 auth_type: pap
261 key: pap
262 source_interface: Ethernet12
263 timeout: 10
264 servers:
265 - host:
266 name: 1.2.3.4
267 auth_type: mschap
268 key: 1234
269 state: replaced
270 #
271 # After state:
272 # ------------
273 #
274 # sonic(config)# do show tacacs-server
275 # ---------------------------------------------------------
276 # TACACS Global Configuration
277 # ---------------------------------------------------------
278 # source-interface : Ethernet12
279 # timeout : 10
280 # auth-type : pap
281 # key configured : Yes
282 # --------------------------------------------------------------------------------------
283 # HOST AUTH-TYPE KEY-CONFIG PORT PRIORITY TIMEOUT VRF
284 # --------------------------------------------------------------------------------------
285 # 1.2.3.4 mschap Yes 49 1 5 default
286 #
287 # Using "overridden" state
288 #
289 # Before state:
290 # -------------
291 #
292 # sonic(config)# do show tacacs-server
293 # ---------------------------------------------------------
294 # TACACS Global Configuration
295 # ---------------------------------------------------------
296 # source-interface : Ethernet12
297 # timeout : 10
298 # auth-type : pap
299 # key configured : Yes
300 # --------------------------------------------------------------------------------------
301 # HOST AUTH-TYPE KEY-CONFIG PORT PRIORITY TIMEOUT VRF
302 # --------------------------------------------------------------------------------------
303 # 1.2.3.4 pap No 49 1 5 default
304 # 11.12.13.14 chap Yes 49 10 5 default
305 #
306 - name: Override tacacs configurations
307 sonic_tacacs_server:
308 config:
309 auth_type: mschap
310 key: mschap
311 source_interface: Ethernet12
312 timeout: 20
313 servers:
314 - host:
315 name: 1.2.3.4
316 auth_type: mschap
317 key: mschap
318 - host:
319 name: 10.10.11.12
320 auth_type: chap
321 timeout: 30
322 priority: 2
323 state: overridden
324 #
325 # After state:
326 # ------------
327 #
328 # sonic(config)# do show tacacs-server
329 # ---------------------------------------------------------
330 # TACACS Global Configuration
331 # ---------------------------------------------------------
332 # source-interface : Ethernet12
333 # timeout : 20
334 # auth-type : mschap
335 # key configured : Yes
336 # --------------------------------------------------------------------------------------
337 # HOST AUTH-TYPE KEY-CONFIG PORT PRIORITY TIMEOUT VRF
338 # --------------------------------------------------------------------------------------
339 # 1.2.3.4 mschap Yes 49 1 5 default
340 # 10.10.11.12 chap No 49 2 30 default
341 #
342 """
343
344 RETURN = """
345 before:
346 description: The configuration prior to the module invocation.
347 returned: always
348 type: list
349 sample: >
350 The configuration returned will always be in the same format
351 as the parameters above.
352 after:
353 description: The resulting configuration module invocation.
354 returned: when changed
355 type: list
356 sample: >
357 The configuration returned will always be in the same format
358 as the parameters above.
359 commands:
360 description: The set of commands pushed to the remote device.
361 returned: always
362 type: list
363 sample: ['command 1', 'command 2', 'command 3']
364 """
365
366
367 from ansible.module_utils.basic import AnsibleModule
368 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.tacacs_server.tacacs_server import Tacacs_serverArgs
369 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.tacacs_server.tacacs_server import Tacacs_server
370
371
372 def main():
373 """
374 Main entry point for module execution
375
376 :returns: the result form module invocation
377 """
378 module = AnsibleModule(argument_spec=Tacacs_serverArgs.argument_spec,
379 supports_check_mode=True)
380
381 result = Tacacs_server(module).execute_module()
382 module.exit_json(**result)
383
384
385 if __name__ == '__main__':
386 main()