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
1c3d642b
Commit
1c3d642b
authored
Nov 10, 2015
by
Zi Chuanxiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed ansible command variables bug.
parent
a2f84e94
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
ansible_api.py
jperm/ansible_api.py
+25
-10
No files found.
jperm/ansible_api.py
View file @
1c3d642b
...
...
@@ -114,7 +114,7 @@ class Command(MyInventory):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
Command
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
run
(
self
,
command
,
module_name
=
"command"
,
timeout
=
5
,
forks
=
10
):
def
run
(
self
,
command
,
module_name
=
"command"
,
timeout
=
5
,
forks
=
10
,
group
=
'my_group'
):
"""
run command from andible ad-hoc.
command : 必须是一个需要执行的命令字符串, 比如
...
...
@@ -127,12 +127,20 @@ class Command(MyInventory):
module_args
=
command
,
timeout
=
timeout
,
inventory
=
self
.
inventory
,
subset
=
'my_group'
,
subset
=
group
,
forks
=
forks
)
self
.
results
=
hoc
.
run
()
return
self
.
stdout
if
self
.
stdout
:
return
{
"ok"
:
self
.
stdout
}
else
:
msg
=
[]
if
self
.
stderr
:
msg
.
append
(
self
.
stderr
)
if
self
.
dark
:
msg
.
append
(
self
.
dark
)
return
{
"failed"
:
msg
}
@property
def
raw_results
(
self
):
...
...
@@ -365,15 +373,23 @@ class App(MyPlaybook):
if
__name__
==
"__main__"
:
resource
=
[{
"hostname"
:
"192.168.10.161"
,
"port"
:
"22"
,
"username"
:
"yumaojun"
,
"password"
:
"yusky0902"
}]
pass
# resource = {
# "group1": {
# "hosts": [{"hostname": "127.0.0.1", "port": "22", "username": "root", "password": "xxx"},],
# "vars" : {"var1": "value1", "var2": "value2"},
# },
# }
# command = Command(resource)
# print command.run("who", group="group1")
# resource = [{"hostname": "127.0.1.1", "port": "22", "username": "root", "password": "xxx"}]
# command = Command(resource)
# print command.run("who")
# playbook = MyPlaybook(resource)
# playbook.run('test.yml')
# print playbook.raw_results
command
=
Command
(
resource
)
command
.
run
(
"who"
)
print
command
.
raw_results
print
command
.
resource
# task = Tasks(resource)
# print task.add_user('test', 'mypass')
...
...
@@ -381,7 +397,6 @@ if __name__ == "__main__":
# print task.push_key('root', '/root/.ssh/id_rsa.pub')
# print task.del_key('root', '/root/.ssh/id_rsa.pub')
# task = Tasks(resource)
# print task.add_init_users()
# print task.del_init_users()
...
...
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