1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #8214/83318c36 backport][stable-9] fix: sudosu not working on some BSD machines (#8631)

fix: sudosu not working on some BSD machines (#8214)

* fix: sudosu not working on some BSD machines

* fix: sudosu: added a flag (`alt_method`) to enhance compatibility with more versions of `su`

* Update changelogs/fragments/8214-sudosu-not-working-on-some-BSD-machines.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/become/sudosu.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/become/sudosu.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/become/sudosu.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/become/sudosu.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* fix: sudosu: lint

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 83318c36aa)

Co-authored-by: leko <rexx0520@gmail.com>
This commit is contained in:
patchback[bot] 2024-07-14 14:22:48 +02:00 committed by GitHub
parent 3b74e9b646
commit 1d9bfc206b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- sudosu become plugin - added an option (``alt_method``) to enhance compatibility with more versions of ``su`` (https://github.com/ansible-collections/community.general/pull/8214).

View file

@ -55,6 +55,21 @@ DOCUMENTATION = """
ini:
- section: sudo_become_plugin
key: password
alt_method:
description:
- Whether to use an alternative method to call C(su). Instead of running C(su -l user /path/to/shell -c command),
it runs C(su -l user -c command).
- Use this when the default one is not working on your system.
required: false
type: boolean
ini:
- section: community.general.sudosu
key: alternative_method
vars:
- name: ansible_sudosu_alt_method
env:
- name: ANSIBLE_SUDOSU_ALT_METHOD
version_added: 9.2.0
"""
@ -89,4 +104,7 @@ class BecomeModule(BecomeBase):
if user:
user = '%s' % (user)
return ' '.join([becomecmd, flags, prompt, 'su -l', user, self._build_success_command(cmd, shell)])
if self.get_option('alt_method'):
return ' '.join([becomecmd, flags, prompt, "su -l", user, "-c", self._build_success_command(cmd, shell, True)])
else:
return ' '.join([becomecmd, flags, prompt, 'su -l', user, self._build_success_command(cmd, shell)])