diff --git a/lib/ansible/modules/identity/opendj/opendj_backendprop.py b/lib/ansible/modules/identity/opendj/opendj_backendprop.py index 25f4d21d81..d28a0ab0f8 100644 --- a/lib/ansible/modules/identity/opendj/opendj_backendprop.py +++ b/lib/ansible/modules/identity/opendj/opendj_backendprop.py @@ -97,8 +97,6 @@ EXAMPLES = ''' RETURN = ''' ''' -import subprocess - class BackendProp(object): def __init__(self, module): @@ -114,9 +112,8 @@ class BackendProp(object): '--backend-name', backend_name, '-n', '-X', '-s' ] + password_method - process = subprocess.Popen(my_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - if process.returncode == 0: + rc, stdout, stderr = self._module.run_command(my_command) + if rc == 0: return stdout else: self._module.fail_json(msg="Error message: " + str(stderr)) @@ -132,9 +129,8 @@ class BackendProp(object): '--set', name + ":" + value, '-n', '-X' ] + password_method - process = subprocess.Popen(my_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - if process.returncode == 0: + rc, stdout, stderr = self._module.run_command(my_command) + if rc == 0: return True else: self._module.fail_json(msg="Error message: " + stderr) diff --git a/lib/ansible/modules/net_tools/lldp.py b/lib/ansible/modules/net_tools/lldp.py index 95ee8272e6..4b7776f021 100644 --- a/lib/ansible/modules/net_tools/lldp.py +++ b/lib/ansible/modules/net_tools/lldp.py @@ -50,13 +50,10 @@ EXAMPLES = ''' ''' -import subprocess - -def gather_lldp(): +def gather_lldp(module): cmd = ['lldpctl', '-f', 'keyvalue'] - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) - (output, err) = proc.communicate() + rc, output, err = module.run_command(cmd) if output: output_dict = {} lldp_entries = output.split("\n") @@ -80,7 +77,7 @@ def gather_lldp(): def main(): module = AnsibleModule({}) - lldp_output = gather_lldp() + lldp_output = gather_lldp(module) try: data = {'lldp': lldp_output['lldp']} module.exit_json(ansible_facts=data) diff --git a/lib/ansible/modules/system/gconftool2.py b/lib/ansible/modules/system/gconftool2.py index 68e174dfce..7efd7c5468 100644 --- a/lib/ansible/modules/system/gconftool2.py +++ b/lib/ansible/modules/system/gconftool2.py @@ -104,12 +104,10 @@ RETURN = ''' ... ''' -from subprocess import Popen, PIPE from ansible.module_utils.basic import AnsibleModule, BOOLEANS_TRUE from ansible.module_utils.pycompat24 import get_exception - class GConf2Preference(object): def __init__(self, ansible, key, value_type, value, direct=False, config_source=""): @@ -158,11 +156,7 @@ class GConf2Preference(object): cmd += "--unset {0}".format(self.key) # Start external command - process = Popen([cmd], stdout=PIPE, stderr=PIPE, shell=True) - - # In either case, we will capture the output - out = process.stdout.read() - err = process.stderr.read() + rc, out, err = self.ansible.run_command(cmd, use_unsafe_shell=True) if len(err) > 0: if fail_onerr: