mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Added command module
This commit is contained in:
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)
|
||||
Reference in New Issue
Block a user