From a76f2d175e87b6331822e6b3c481de2b537d6018 Mon Sep 17 00:00:00 2001 From: Jon Ellis Date: Mon, 6 Jun 2022 22:35:31 +0100 Subject: [PATCH] Replace use of subprocess.Popen with module.run_command --- plugins/modules/system/sudoers.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/modules/system/sudoers.py b/plugins/modules/system/sudoers.py index 775c44260d..9cb07aa085 100644 --- a/plugins/modules/system/sudoers.py +++ b/plugins/modules/system/sudoers.py @@ -117,6 +117,8 @@ from ansible.module_utils.common.text.converters import to_native class Sudoers(object): def __init__(self, module): + self.module = module + self.check_mode = module.check_mode self.name = module.params['name'] self.user = module.params['user'] @@ -162,14 +164,10 @@ class Sudoers(object): return "{owner} ALL={runas}{nopasswd} {commands}\n".format(owner=owner, runas=runas_str, nopasswd=nopasswd_str, commands=commands_str) def validate(self): - # fork to visudo - content = bytes(self.content(), 'utf-8') check_command = ['visudo', '-c', '-f', '-'] + rc, stdout, stderr = self.module.run_command(check_command, data=self.content()) - check = subprocess.Popen(check_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = check.communicate(input=content) - - if check.returncode != 0: + if rc != 0: raise Exception('Failed to validate sudoers rule:\n{stdout}'.format(stdout=stdout)) def run(self):