This standardizes the apt_key module some

* improves error handling and reporting
* uses run_command to reduce code
* fails quicker on errors as opposed to return codes and tracebacks
* can now also specify the key as data versus needing to wget it from a file
This commit is contained in:
Michael DeHaan 2013-01-28 15:41:46 -05:00
parent 0bfec51a04
commit 4d8f3b0924
2 changed files with 82 additions and 103 deletions

View file

@ -677,7 +677,7 @@ class AnsibleModule(object):
self.set_context_if_different(src, context, False)
os.rename(src, dest)
def run_command(self, args, check_rc=False, close_fds=False, executable=None):
def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None):
'''
Execute a command, returns rc, stdout, and stderr.
args is the command to run
@ -700,12 +700,20 @@ class AnsibleModule(object):
self.fail_json(rc=257, cmd=args, msg=msg)
rc = 0
msg = None
st_in = None
if data:
st_in = subprocess.PIPE
try:
cmd = subprocess.Popen(args,
executable=executable,
shell=shell,
close_fds=close_fds,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdin=st_in,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if data:
cmd.stdin.write(data)
cmd.stdin.write('\\n')
out, err = cmd.communicate()
rc = cmd.returncode
except (OSError, IOError), e: