Debian Codegraph @

ansible_collections/community/general/plugins/become/pmrun.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: pmrun
8 short_description: Privilege Manager run
9 description:
10 - This become plugins allows your remote/login user to execute commands as another user using the C(pmrun) utility.
11 author: Ansible Core Team
12 options:
13 become_exe:
14 description: C(pmrun) executable.
15 type: string
16 default: pmrun
17 ini:
18 - section: privilege_escalation
19 key: become_exe
20 - section: pmrun_become_plugin
21 key: executable
22 vars:
23 - name: ansible_become_exe
24 - name: ansible_pmrun_exe
25 env:
26 - name: ANSIBLE_BECOME_EXE
27 - name: ANSIBLE_PMRUN_EXE
28 become_flags:
29 description: Options to pass to C(pmrun).
30 type: string
31 default: ''
32 ini:
33 - section: privilege_escalation
34 key: become_flags
35 - section: pmrun_become_plugin
36 key: flags
37 vars:
38 - name: ansible_become_flags
39 - name: ansible_pmrun_flags
40 env:
41 - name: ANSIBLE_BECOME_FLAGS
42 - name: ANSIBLE_PMRUN_FLAGS
43 become_pass:
44 description: C(pmrun) password.
45 type: string
46 required: false
47 vars:
48 - name: ansible_become_password
49 - name: ansible_become_pass
50 - name: ansible_pmrun_pass
51 env:
52 - name: ANSIBLE_BECOME_PASS
53 - name: ANSIBLE_PMRUN_PASS
54 ini:
55 - section: pmrun_become_plugin
56 key: password
57 notes:
58 - This plugin ignores the C(become_user) supplied and uses C(pmrun)'s own configuration to select the user.
59 """
60
61 from shlex import quote as shlex_quote
62
63 from ansible.plugins.become import BecomeBase
64
65
66 class BecomeModule(BecomeBase):
67 name = "community.general.pmrun"
68 prompt = "Enter UPM user password:"
69
70 def build_become_command(self, cmd, shell):
71 super().build_become_command(cmd, shell)
72
73 if not cmd:
74 return cmd
75
76 become = self.get_option("become_exe")
77
78 flags = self.get_option("become_flags")
79 return f"{become} {flags} {shlex_quote(self._build_success_command(cmd, shell))}"