mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Replace use of subprocess.Popen with module.run_command
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user