From 15e9f04f866c3abc7de0a5baa8635baaeb149b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 29 Jul 2020 01:55:01 -0400 Subject: [PATCH] doas: properly set the default values (#704) * doas: properly set the default values The module expects by default: - `become_user` to be `None` or a string, - `become_flags` to by an empty string. * Apply suggestions from code review Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../fragments/704-doas-set-correct-default-values.yml | 2 ++ plugins/become/doas.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/704-doas-set-correct-default-values.yml diff --git a/changelogs/fragments/704-doas-set-correct-default-values.yml b/changelogs/fragments/704-doas-set-correct-default-values.yml new file mode 100644 index 0000000000..db1b4d3c4a --- /dev/null +++ b/changelogs/fragments/704-doas-set-correct-default-values.yml @@ -0,0 +1,2 @@ +bugfixes: +- doas become plugin - address a bug with the parameters handling that was breaking the plugin in community.general when `become_flags` and `become_user` were not explicitly specified (https://github.com/ansible-collections/community.general/pull/704). diff --git a/plugins/become/doas.py b/plugins/become/doas.py index 08b6361b4d..d7f4ad81c8 100644 --- a/plugins/become/doas.py +++ b/plugins/become/doas.py @@ -40,7 +40,7 @@ DOCUMENTATION = ''' - name: ANSIBLE_DOAS_EXE become_flags: description: Options to pass to doas - default: + default: '' ini: - section: privilege_escalation key: become_flags @@ -117,9 +117,8 @@ class BecomeModule(BecomeBase): if not self.get_option('become_pass') and '-n' not in flags: flags += ' -n' - user = self.get_option('become_user') - if user: - user = '-u %s' % (user) + become_user = self.get_option('become_user') + user = '-u %s' % (become_user) if become_user else '' success_cmd = self._build_success_command(cmd, shell, noexe=True) executable = getattr(shell, 'executable', shell.SHELL_FAMILY)