Fixed modules using Popen (#24558)

* Fixed modules using Popen

* Reverted change in mysql_db, Popen is required to pipe compressed archives to mysql
pull/26011/head
Andrea Tartaglia 8 years ago committed by Toshio Kuratomi
parent 495a809f46
commit 921bc0599b

@ -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)

@ -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)

@ -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:

Loading…
Cancel
Save