mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 05:09:12 +00:00
pfexec become plugin: fix broken defaults for illumos/SmartOS
The pfexec become plugin has had incorrect defaults since it was migrated from Ansible core, making it unusable on illumos without manual workarounds: 1. become_flags defaulted to '-H -S -n' which are sudo flags. pfexec does not accept any of these options, causing: 'exec: illegal option -- H' 2. wrap_exe defaulted to false. Unlike sudo, pfexec does not interpret shell constructs internally. Since Ansible generates compound commands (echo BECOME-SUCCESS-xxx ; python3), these must be wrapped in /bin/sh -c for pfexec to execute them. These issues were originally reported in 2016 (ansible/ansible#15642), migrated to community.general as #3671, and partially fixed by PR #3889 in 2022 (which corrected quoting but not the defaults). Users have had to work around this with explicit inventory settings ever since. Changes: - become_flags default: '-H -S -n' -> '' (empty) - wrap_exe default: false -> true - build_become_command: handle empty flags cleanly - Updated tests to match corrected defaults - Added test for custom flags - Improved wrap_exe description to explain why it should be enabled
This commit is contained in:
parent
25b5655be7
commit
7eaf551b24
3 changed files with 48 additions and 13 deletions
|
|
@ -46,7 +46,7 @@ options:
|
|||
become_flags:
|
||||
description: Options to pass to C(pfexec).
|
||||
type: string
|
||||
default: -H -S -n
|
||||
default: ""
|
||||
ini:
|
||||
- section: privilege_escalation
|
||||
key: become_flags
|
||||
|
|
@ -73,8 +73,12 @@ options:
|
|||
- section: pfexec_become_plugin
|
||||
key: password
|
||||
wrap_exe:
|
||||
description: Toggle to wrap the command C(pfexec) calls in C(shell -c) or not.
|
||||
default: false
|
||||
description:
|
||||
- Toggle to wrap the command C(pfexec) calls in C(shell -c) or not.
|
||||
- Unlike C(sudo), C(pfexec) does not interpret shell constructs internally,
|
||||
so commands containing shell operators must be wrapped in a shell invocation.
|
||||
- This should generally be left enabled.
|
||||
default: true
|
||||
type: bool
|
||||
ini:
|
||||
- section: pfexec_become_plugin
|
||||
|
|
@ -103,4 +107,7 @@ class BecomeModule(BecomeBase):
|
|||
|
||||
flags = self.get_option("become_flags")
|
||||
noexe = not self.get_option("wrap_exe")
|
||||
return f"{exe} {flags} {self._build_success_command(cmd, shell, noexe=noexe)}"
|
||||
become_cmd = self._build_success_command(cmd, shell, noexe=noexe)
|
||||
if flags:
|
||||
return f"{exe} {flags} {become_cmd}"
|
||||
return f"{exe} {become_cmd}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue