Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
fe23e610
Commit
fe23e610
authored
Oct 30, 2015
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Task add method push_key
parent
b88c4211
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
7 deletions
+58
-7
ansible_api.py
jperm/ansible_api.py
+58
-7
No files found.
jperm/ansible_api.py
View file @
fe23e610
...
@@ -97,6 +97,7 @@ class Command(MyInventory):
...
@@ -97,6 +97,7 @@ class Command(MyInventory):
)
)
self
.
results
=
hoc
.
run
()
self
.
results
=
hoc
.
run
()
return
self
.
stdout
@property
@property
...
@@ -163,6 +164,60 @@ class Tasks(Command):
...
@@ -163,6 +164,60 @@ class Tasks(Command):
super
(
Tasks
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
Tasks
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
__run
(
self
,
module_args
,
module_name
=
"command"
,
timeout
=
5
,
forks
=
10
):
"""
run command from andible ad-hoc.
command : 必须是一个需要执行的命令字符串, 比如
'uname -a'
"""
hoc
=
Runner
(
module_name
=
module_name
,
module_args
=
module_args
,
timeout
=
timeout
,
inventory
=
self
.
inventory
,
subset
=
'my_group'
,
forks
=
forks
)
self
.
results
=
hoc
.
run
()
def
push_key
(
self
,
user
,
key_path
):
"""
push the ssh authorized key to target.
"""
module_args
=
'user="
%
s" key="{{ lookup("file", "
%
s") }}"'
%
(
user
,
key_path
)
self
.
__run
(
module_args
,
"authorized_key"
)
msg
=
{}
for
result
in
[
"contacted"
,
"dark"
]:
all
=
self
.
results
.
get
(
result
)
for
key
,
value
in
all
.
iteritems
():
if
value
.
get
(
"msg"
):
msg
[
key
]
=
value
.
get
(
"msg"
)
if
not
msg
:
return
{
"status"
:
"ok"
}
else
:
return
{
"status"
:
"failed"
,
"msg"
:
msg
}
def
add_user
(
self
,
user
):
"""
add a host user.
"""
pass
def
del_user
(
self
,
user
):
"""
delete a host user.
"""
pass
class
MyPlaybook
(
MyInventory
):
class
MyPlaybook
(
MyInventory
):
"""
"""
this is my playbook object for execute playbook.
this is my playbook object for execute playbook.
...
@@ -188,13 +243,9 @@ class App(MyPlaybook):
...
@@ -188,13 +243,9 @@ class App(MyPlaybook):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
resource
=
[{
"hostname"
:
"127.0.0.1"
,
"port"
:
"22"
,
"username"
:
"root"
,
"password"
:
"xxx"
},
resource
=
[
{
"hostname"
:
"192.168.10.128"
,
"port"
:
"22"
,
"username"
:
"root"
,
"password"
:
"xxx"
}]
{
"hostname"
:
"192.168.10.128"
,
"port"
:
"22"
,
"username"
:
"root"
,
"password"
:
"xxx"
}]
task
=
Tasks
(
resource
)
command
=
Command
(
resource
)
print
task
.
push_key
(
'root'
,
'/root/.ssh/id_rsa.pub'
)
command
.
run
(
"uname -a"
,
"copy"
)
print
command
.
stdout
print
command
.
stderr
print
command
.
dark
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment