mirror of https://github.com/jumpserver/jumpserver
定义通用模块执行
parent
ab313aacd8
commit
eea56ea0e5
|
@ -82,11 +82,13 @@ class MyInventory(object):
|
||||||
hostport = host.get("port")
|
hostport = host.get("port")
|
||||||
username = host.get("username")
|
username = host.get("username")
|
||||||
password = host.get("password")
|
password = host.get("password")
|
||||||
|
ssh_key = host.get("ssh_key")
|
||||||
my_host = Host(name=hostname, port=hostport)
|
my_host = Host(name=hostname, port=hostport)
|
||||||
my_host.set_variable('ansible_ssh_host', hostname)
|
my_host.set_variable('ansible_ssh_host', hostname)
|
||||||
my_host.set_variable('ansible_ssh_port', hostport)
|
my_host.set_variable('ansible_ssh_port', hostport)
|
||||||
my_host.set_variable('ansible_ssh_user', username)
|
my_host.set_variable('ansible_ssh_user', username)
|
||||||
my_host.set_variable('ansible_ssh_pass', password)
|
my_host.set_variable('ansible_ssh_pass', password)
|
||||||
|
my_host.set_variable('ansible_ssh_private_key_file', ssh_key)
|
||||||
# set other variables
|
# set other variables
|
||||||
for key, value in host.iteritems():
|
for key, value in host.iteritems():
|
||||||
if key not in ["hostname", "port", "username", "password"]:
|
if key not in ["hostname", "port", "username", "password"]:
|
||||||
|
@ -156,12 +158,12 @@ class Command(MyInventory):
|
||||||
if module_name not in ["raw", "command", "shell"]:
|
if module_name not in ["raw", "command", "shell"]:
|
||||||
raise CommandValueError("module_name",
|
raise CommandValueError("module_name",
|
||||||
"module_name must be of the 'raw, command, shell'")
|
"module_name must be of the 'raw, command, shell'")
|
||||||
hoc = MyRunner(module_name=module_name,
|
hoc = Runner(module_name=module_name,
|
||||||
module_args=command,
|
module_args=command,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
inventory=self.inventory,
|
inventory=self.inventory,
|
||||||
pattern=pattern,
|
pattern=pattern,
|
||||||
forks=forks,
|
forks=forks,
|
||||||
)
|
)
|
||||||
self.results = hoc.run()
|
self.results = hoc.run()
|
||||||
|
|
||||||
|
@ -418,8 +420,6 @@ class Tasks(Command):
|
||||||
return {"status": "failed", "msg": self.msg} if self.msg else {"status": "ok", "result": result}
|
return {"status": "failed", "msg": self.msg} if self.msg else {"status": "ok", "result": result}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CustomAggregateStats(callbacks.AggregateStats):
|
class CustomAggregateStats(callbacks.AggregateStats):
|
||||||
"""
|
"""
|
||||||
Holds stats about per-host activity during playbook runs.
|
Holds stats about per-host activity during playbook runs.
|
||||||
|
@ -438,7 +438,6 @@ class CustomAggregateStats(callbacks.AggregateStats):
|
||||||
|
|
||||||
self.results.append(runner_results)
|
self.results.append(runner_results)
|
||||||
|
|
||||||
|
|
||||||
def summarize(self, host):
|
def summarize(self, host):
|
||||||
"""
|
"""
|
||||||
Return information about a particular host
|
Return information about a particular host
|
||||||
|
|
|
@ -10,6 +10,11 @@ from jperm.models import PermRole
|
||||||
from jperm.models import PermRule
|
from jperm.models import PermRule
|
||||||
|
|
||||||
|
|
||||||
|
class PermGet(object):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_object_list(model, id_list):
|
def get_object_list(model, id_list):
|
||||||
"""根据id列表获取对象列表"""
|
"""根据id列表获取对象列表"""
|
||||||
object_list = []
|
object_list = []
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import os, sys, time, re
|
import os, sys, time, re
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
import crypt
|
import crypt
|
||||||
|
import pwd
|
||||||
from binascii import b2a_hex, a2b_hex
|
from binascii import b2a_hex, a2b_hex
|
||||||
import hashlib
|
import hashlib
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -44,6 +45,14 @@ def set_log(level):
|
||||||
return logger_f
|
return logger_f
|
||||||
|
|
||||||
|
|
||||||
|
def chown(path, user, group='', ):
|
||||||
|
if not group:
|
||||||
|
group = user
|
||||||
|
uid = pwd.getpwnam(user).pwd_uid
|
||||||
|
gid = pwd.getpwnam(group).gr_gid
|
||||||
|
os.chown(path, uid, gid)
|
||||||
|
|
||||||
|
|
||||||
def page_list_return(total, current=1):
|
def page_list_return(total, current=1):
|
||||||
"""
|
"""
|
||||||
page
|
page
|
||||||
|
@ -390,7 +399,7 @@ def bash(cmd):
|
||||||
return subprocess.call(cmd, shell=True)
|
return subprocess.call(cmd, shell=True)
|
||||||
|
|
||||||
|
|
||||||
def mkdir(dir_name, username='root', mode=0755):
|
def mkdir(dir_name, username='', mode=0755):
|
||||||
"""
|
"""
|
||||||
insure the dir exist and mode ok
|
insure the dir exist and mode ok
|
||||||
目录存在,如果不存在就建立,并且权限正确
|
目录存在,如果不存在就建立,并且权限正确
|
||||||
|
@ -399,7 +408,7 @@ def mkdir(dir_name, username='root', mode=0755):
|
||||||
os.makedirs(dir_name)
|
os.makedirs(dir_name)
|
||||||
os.chmod(dir_name, mode)
|
os.chmod(dir_name, mode)
|
||||||
if username:
|
if username:
|
||||||
bash('chown %s:%s %s' % (username, username, dir_name))
|
chown(dir_name, username)
|
||||||
|
|
||||||
|
|
||||||
def http_success(request, msg):
|
def http_success(request, msg):
|
||||||
|
|
|
@ -143,7 +143,7 @@ def gen_ssh_key(username, password='',
|
||||||
with open(authorized_key_file, 'w') as auth_f:
|
with open(authorized_key_file, 'w') as auth_f:
|
||||||
auth_f.write(pub_f.read())
|
auth_f.write(pub_f.read())
|
||||||
os.chmod(authorized_key_file, 0600)
|
os.chmod(authorized_key_file, 0600)
|
||||||
bash('chown %s:%s %s' % (username, username, authorized_key_file))
|
chown(authorized_key_file, username)
|
||||||
|
|
||||||
|
|
||||||
def server_add_user(username, password, ssh_key_pwd, ssh_key_login_need):
|
def server_add_user(username, password, ssh_key_pwd, ssh_key_login_need):
|
||||||
|
|
Loading…
Reference in New Issue