Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Issue #529: become plugin podman_unshare become_user default #530

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions plugins/become/podman_unshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
version_added: 1.9.0
options:
become_user:
description: User you 'become' to execute the task
default: root
description: User you 'become' to execute the task ('root' is not a valid value here).
ini:
- section: privilege_escalation
key: become_user
Expand Down Expand Up @@ -130,8 +129,8 @@ def build_become_command(self, cmd, shell):

becomecmd = 'podman unshare'

user = self.get_option('become_user') or ''
if user:
user = self.get_option('become_user') or 'root'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be the current user by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will run as the current user (ansible_user) if become_user is root, or not set at all (by default).
Actually, if become_user has been set to anything but root it will be executed with sudo, otherwise no sudo applied.
I tested it and was working flawlessly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarification. I think we can add some tests here.
I'll prepare a test skeleton.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use this as a template for tests: #531 Just replace podman_lovely_module by your module/plugin name everywhere.

if user != 'root':
sshnaidm marked this conversation as resolved.
Show resolved Hide resolved
cmdlist = [self.get_option('become_exe') or 'sudo']
# -i is required, because
# podman unshare should be executed in a login shell to avoid chdir permission errors
Expand Down