Added command module
This commit is contained in:
parent
f4fca1069a
commit
a2a8deaeaa
2 changed files with 31 additions and 8 deletions
12
README.md
12
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
|
||||
|
|
27
library/command
Executable file
27
library/command
Executable 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)
|
Loading…
Reference in a new issue