Added command module

This commit is contained in:
Michael DeHaan 2012-02-23 17:19:06 -05:00
parent f4fca1069a
commit a2a8deaeaa
2 changed files with 31 additions and 8 deletions

View file

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

27
library/command Executable file
View file

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