Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
guo xiaoyong
Jumpserver
Commits
14b85458
Commit
14b85458
authored
4 years ago
by
ibuler
Committed by
Jiangjie.Bai
4 years ago
Browse files
Options
Download
Email Patches
Plain Diff
fix(ops): 修复因为更改controlmaster引起的连接不服用维内托
parent
5c3f92cd
v2.2
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/ops/ansible/callback.py
+7
-1
apps/ops/ansible/callback.py
apps/ops/ansible/runner.py
+8
-0
apps/ops/ansible/runner.py
with
15 additions
and
1 deletion
+15
-1
apps/ops/ansible/callback.py
+
7
-
1
View file @
14b85458
...
...
@@ -65,6 +65,8 @@ class AdHocResultCallback(CallbackMixin, CallbackModule, CMDCallBackModule):
"""
Task result Callback
"""
context
=
None
def
clean_result
(
self
,
t
,
host
,
task_name
,
task_result
):
contacted
=
self
.
results_summary
[
"contacted"
]
dark
=
self
.
results_summary
[
"dark"
]
...
...
@@ -133,7 +135,11 @@ class AdHocResultCallback(CallbackMixin, CallbackModule, CMDCallBackModule):
pass
def
set_play_context
(
self
,
context
):
context
.
ssh_args
=
'-C -o ControlMaster=no'
# for k, v in context._attributes.items():
# print("{} ==> {}".format(k, v))
if
self
.
context
and
isinstance
(
self
.
context
,
dict
):
for
k
,
v
in
self
.
context
.
items
():
setattr
(
context
,
k
,
v
)
class
CommandResultCallback
(
AdHocResultCallback
):
...
...
This diff is collapsed.
Click to expand it.
apps/ops/ansible/runner.py
+
8
-
0
View file @
14b85458
...
...
@@ -182,6 +182,13 @@ class AdHocRunner:
_options
.
update
(
options
)
return
_options
def
set_control_master_if_need
(
self
,
cleaned_tasks
):
modules
=
[
task
.
get
(
'action'
,
{}).
get
(
'module'
)
for
task
in
cleaned_tasks
]
if
{
'ping'
,
'win_ping'
}
&
set
(
modules
):
self
.
results_callback
.
context
=
{
'ssh_args'
:
'-C -o ControlMaster=no'
}
def
run
(
self
,
tasks
,
pattern
,
play_name
=
'Ansible Ad-hoc'
,
gather_facts
=
'no'
):
"""
:param tasks: [{'action': {'module': 'shell', 'args': 'ls'}, ...}, ]
...
...
@@ -193,6 +200,7 @@ class AdHocRunner:
self
.
check_pattern
(
pattern
)
self
.
results_callback
=
self
.
get_result_callback
()
cleaned_tasks
=
self
.
clean_tasks
(
tasks
)
self
.
set_control_master_if_need
(
cleaned_tasks
)
context
.
CLIARGS
=
ImmutableDict
(
self
.
options
)
play_source
=
dict
(
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help