Debian Codegraph @

ansible_collections/community/general/plugins/become/sesu.py

raw
1 # Copyright (c) 2018, Ansible Project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 from __future__ import annotations
5
6 DOCUMENTATION = r"""
7 name: sesu
8 short_description: CA Privileged Access Manager
9 description:
10 - This become plugins allows your remote/login user to execute commands as another user using the C(sesu) utility.
11 author: ansible (@nekonyuu)
12 options:
13 become_user:
14 description: User you 'become' to execute the task.
15 type: string
16 default: ''
17 ini:
18 - section: privilege_escalation
19 key: become_user
20 - section: sesu_become_plugin
21 key: user
22 vars:
23 - name: ansible_become_user
24 - name: ansible_sesu_user
25 env:
26 - name: ANSIBLE_BECOME_USER
27 - name: ANSIBLE_SESU_USER
28 become_exe:
29 description: C(sesu) executable.
30 type: string
31 default: sesu
32 ini:
33 - section: privilege_escalation
34 key: become_exe
35 - section: sesu_become_plugin
36 key: executable
37 vars:
38 - name: ansible_become_exe
39 - name: ansible_sesu_exe
40 env:
41 - name: ANSIBLE_BECOME_EXE
42 - name: ANSIBLE_SESU_EXE
43 become_flags:
44 description: Options to pass to C(sesu).
45 type: string
46 default: -H -S -n
47 ini:
48 - section: privilege_escalation
49 key: become_flags
50 - section: sesu_become_plugin
51 key: flags
52 vars:
53 - name: ansible_become_flags
54 - name: ansible_sesu_flags
55 env:
56 - name: ANSIBLE_BECOME_FLAGS
57 - name: ANSIBLE_SESU_FLAGS
58 become_pass:
59 description: Password to pass to C(sesu).
60 type: string
61 required: false
62 vars:
63 - name: ansible_become_password
64 - name: ansible_become_pass
65 - name: ansible_sesu_pass
66 env:
67 - name: ANSIBLE_BECOME_PASS
68 - name: ANSIBLE_SESU_PASS
69 ini:
70 - section: sesu_become_plugin
71 key: password
72 """
73
74 from ansible.plugins.become import BecomeBase
75
76
77 class BecomeModule(BecomeBase):
78 name = "community.general.sesu"
79
80 prompt = "Please enter your password:"
81 fail = missing = ("Sorry, try again with sesu.",)
82
83 def build_become_command(self, cmd, shell):
84 super().build_become_command(cmd, shell)
85
86 if not cmd:
87 return cmd
88
89 become = self.get_option("become_exe")
90
91 flags = self.get_option("become_flags")
92 user = self.get_option("become_user")
93 return f"{become} {flags} {user} -c {self._build_success_command(cmd, shell)}"