From a2a8deaeaa12122f94ec7f0b820adce051f2a5f5 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 23 Feb 2012 17:19:06 -0500 Subject: [PATCH] Added command module --- README.md | 12 ++++-------- library/command | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100755 library/command diff --git a/README.md b/README.md index f387f453b8..1a6f42fa7e 100644 --- a/README.md +++ b/README.md @@ -121,18 +121,14 @@ up around the library scripts. Existing library modules ======================== - * ping - * facter - -Modules in Progress -=================== - - * command -- gives output, return code, and time - * many others -- users, groups, files + * command -- runs commands, giving output, return codes, and run time info + * ping - just returns if the system is up or not + * facter - retrieves facts about the host OS Future plans ============ + * modules for users, groups, and files, using puppet style ensure mechanics * inventory gathering (w/ accompanying ansible-inventory & RSS) * very simple option constructing/parsing for modules * Dead-simple declarative configuration management engine using diff --git a/library/command b/library/command new file mode 100755 index 0000000000..53a8d6ffff --- /dev/null +++ b/library/command @@ -0,0 +1,27 @@ +#!/usr/bin/python + +import json +import subprocess +import sys +import datetime + +args = sys.argv[1:] +startd = datetime.datetime.now() + +cmd = subprocess.Popen(args, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + +out, err = cmd.communicate() +endd = datetime.datetime.now() +delta = endd - startd + +result = { + "stdout" : out, + "stderr" : err, + "rc" : cmd.returncode, + "start" : str(startd), + "end" : str(endd), + "delta" : str(delta), +} + +print json.dumps(result)