Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
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
OpenEdx
ansible
Commits
56f9328f
Commit
56f9328f
authored
Aug 11, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge
parent
b3371b8d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
14 deletions
+19
-14
lib/ansible/runner/__init__.py
+19
-14
No files found.
lib/ansible/runner/__init__.py
View file @
56f9328f
...
@@ -47,6 +47,8 @@ from return_data import ReturnData
...
@@ -47,6 +47,8 @@ from return_data import ReturnData
from
ansible.callbacks
import
DefaultRunnerCallbacks
,
vv
from
ansible.callbacks
import
DefaultRunnerCallbacks
,
vv
from
ansible.module_common
import
ModuleReplacer
from
ansible.module_common
import
ModuleReplacer
from
ansible.module_utils.splitter
import
split_args
from
ansible.module_utils.splitter
import
split_args
from
ansible.cache
import
FactCache
from
ansible.utils
import
update_hash
module_replacer
=
ModuleReplacer
(
strip_comments
=
False
)
module_replacer
=
ModuleReplacer
(
strip_comments
=
False
)
...
@@ -57,7 +59,7 @@ except ImportError:
...
@@ -57,7 +59,7 @@ except ImportError:
HAS_ATFORK
=
False
HAS_ATFORK
=
False
multiprocessing_runner
=
None
multiprocessing_runner
=
None
OUTPUT_LOCKFILE
=
tempfile
.
TemporaryFile
()
OUTPUT_LOCKFILE
=
tempfile
.
TemporaryFile
()
PROCESS_LOCKFILE
=
tempfile
.
TemporaryFile
()
PROCESS_LOCKFILE
=
tempfile
.
TemporaryFile
()
...
@@ -87,7 +89,7 @@ class HostVars(dict):
...
@@ -87,7 +89,7 @@ class HostVars(dict):
def
__init__
(
self
,
vars_cache
,
inventory
,
vault_password
=
None
):
def
__init__
(
self
,
vars_cache
,
inventory
,
vault_password
=
None
):
self
.
vars_cache
=
vars_cache
self
.
vars_cache
=
vars_cache
self
.
inventory
=
inventory
self
.
inventory
=
inventory
self
.
lookup
=
dict
()
self
.
lookup
=
{}
self
.
update
(
vars_cache
)
self
.
update
(
vars_cache
)
self
.
vault_password
=
vault_password
self
.
vault_password
=
vault_password
...
@@ -158,7 +160,7 @@ class Runner(object):
...
@@ -158,7 +160,7 @@ class Runner(object):
# storage & defaults
# storage & defaults
self
.
check
=
check
self
.
check
=
check
self
.
diff
=
diff
self
.
diff
=
diff
self
.
setup_cache
=
utils
.
default
(
setup_cache
,
lambda
:
collections
.
defaultdict
(
dict
))
self
.
setup_cache
=
utils
.
default
(
setup_cache
,
lambda
:
ansible
.
cache
.
FactCache
(
))
self
.
vars_cache
=
utils
.
default
(
vars_cache
,
lambda
:
collections
.
defaultdict
(
dict
))
self
.
vars_cache
=
utils
.
default
(
vars_cache
,
lambda
:
collections
.
defaultdict
(
dict
))
self
.
basedir
=
utils
.
default
(
basedir
,
lambda
:
os
.
getcwd
())
self
.
basedir
=
utils
.
default
(
basedir
,
lambda
:
os
.
getcwd
())
self
.
callbacks
=
utils
.
default
(
callbacks
,
lambda
:
DefaultRunnerCallbacks
())
self
.
callbacks
=
utils
.
default
(
callbacks
,
lambda
:
DefaultRunnerCallbacks
())
...
@@ -205,11 +207,11 @@ class Runner(object):
...
@@ -205,11 +207,11 @@ class Runner(object):
# if the transport is 'smart' see if SSH can support ControlPersist if not use paramiko
# if the transport is 'smart' see if SSH can support ControlPersist if not use paramiko
# 'smart' is the default since 1.2.1/1.3
# 'smart' is the default since 1.2.1/1.3
cmd
=
subprocess
.
Popen
([
'ssh'
,
'-o'
,
'ControlPersist'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
cmd
=
subprocess
.
Popen
([
'ssh'
,
'-o'
,
'ControlPersist'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
cmd
.
communicate
()
(
out
,
err
)
=
cmd
.
communicate
()
if
"Bad configuration option"
in
err
:
if
"Bad configuration option"
in
err
:
self
.
transport
=
"paramiko"
self
.
transport
=
"paramiko"
else
:
else
:
self
.
transport
=
"ssh"
self
.
transport
=
"ssh"
# save the original transport, in case it gets
# save the original transport, in case it gets
# changed later via options like accelerate
# changed later via options like accelerate
...
@@ -308,7 +310,7 @@ class Runner(object):
...
@@ -308,7 +310,7 @@ class Runner(object):
delegate
=
{}
delegate
=
{}
# allow delegated host to be templated
# allow delegated host to be templated
delegate
[
'host'
]
=
template
.
template
(
self
.
basedir
,
host
,
delegate
[
'host'
]
=
template
.
template
(
self
.
basedir
,
host
,
remote_inject
,
fail_on_undefined
=
True
)
remote_inject
,
fail_on_undefined
=
True
)
delegate
[
'inject'
]
=
remote_inject
.
copy
()
delegate
[
'inject'
]
=
remote_inject
.
copy
()
...
@@ -331,7 +333,7 @@ class Runner(object):
...
@@ -331,7 +333,7 @@ class Runner(object):
# make sure the inject is empty for non-inventory hosts
# make sure the inject is empty for non-inventory hosts
this_info
=
{}
this_info
=
{}
# get the real ssh_address for the delegate
# get the real ssh_address for the delegate
# and allow ansible_ssh_host to be templated
# and allow ansible_ssh_host to be templated
delegate
[
'ssh_host'
]
=
template
.
template
(
self
.
basedir
,
delegate
[
'ssh_host'
]
=
template
.
template
(
self
.
basedir
,
this_info
.
get
(
'ansible_ssh_host'
,
this_host
),
this_info
.
get
(
'ansible_ssh_host'
,
this_host
),
...
@@ -342,7 +344,7 @@ class Runner(object):
...
@@ -342,7 +344,7 @@ class Runner(object):
delegate
[
'user'
]
=
self
.
_compute_delegate_user
(
this_host
,
delegate
[
'inject'
])
delegate
[
'user'
]
=
self
.
_compute_delegate_user
(
this_host
,
delegate
[
'inject'
])
delegate
[
'pass'
]
=
this_info
.
get
(
'ansible_ssh_pass'
,
password
)
delegate
[
'pass'
]
=
this_info
.
get
(
'ansible_ssh_pass'
,
password
)
delegate
[
'private_key_file'
]
=
this_info
.
get
(
'ansible_ssh_private_key_file'
,
delegate
[
'private_key_file'
]
=
this_info
.
get
(
'ansible_ssh_private_key_file'
,
self
.
private_key_file
)
self
.
private_key_file
)
delegate
[
'transport'
]
=
this_info
.
get
(
'ansible_connection'
,
self
.
transport
)
delegate
[
'transport'
]
=
this_info
.
get
(
'ansible_connection'
,
self
.
transport
)
delegate
[
'sudo_pass'
]
=
this_info
.
get
(
'ansible_sudo_pass'
,
self
.
sudo_pass
)
delegate
[
'sudo_pass'
]
=
this_info
.
get
(
'ansible_sudo_pass'
,
self
.
sudo_pass
)
...
@@ -588,6 +590,7 @@ class Runner(object):
...
@@ -588,6 +590,7 @@ class Runner(object):
# merge the VARS and SETUP caches for this host
# merge the VARS and SETUP caches for this host
combined_cache
=
self
.
setup_cache
.
copy
()
combined_cache
=
self
.
setup_cache
.
copy
()
combined_cache
.
setdefault
(
host
,
{})
.
update
(
self
.
vars_cache
.
get
(
host
,
{}))
combined_cache
.
setdefault
(
host
,
{})
.
update
(
self
.
vars_cache
.
get
(
host
,
{}))
hostvars
=
HostVars
(
combined_cache
,
self
.
inventory
,
vault_password
=
self
.
vault_pass
)
hostvars
=
HostVars
(
combined_cache
,
self
.
inventory
,
vault_password
=
self
.
vault_pass
)
# use combined_cache and host_variables to template the module_vars
# use combined_cache and host_variables to template the module_vars
...
@@ -890,6 +893,7 @@ class Runner(object):
...
@@ -890,6 +893,7 @@ class Runner(object):
until
=
self
.
module_vars
.
get
(
'until'
,
None
)
until
=
self
.
module_vars
.
get
(
'until'
,
None
)
if
until
is
not
None
and
result
.
comm_ok
:
if
until
is
not
None
and
result
.
comm_ok
:
inject
[
self
.
module_vars
.
get
(
'register'
)]
=
result
.
result
inject
[
self
.
module_vars
.
get
(
'register'
)]
=
result
.
result
cond
=
template
.
template
(
self
.
basedir
,
until
,
inject
,
expand_lists
=
False
)
cond
=
template
.
template
(
self
.
basedir
,
until
,
inject
,
expand_lists
=
False
)
if
not
utils
.
check_conditional
(
cond
,
self
.
basedir
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
):
if
not
utils
.
check_conditional
(
cond
,
self
.
basedir
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
):
retries
=
self
.
module_vars
.
get
(
'retries'
)
retries
=
self
.
module_vars
.
get
(
'retries'
)
...
@@ -910,7 +914,7 @@ class Runner(object):
...
@@ -910,7 +914,7 @@ class Runner(object):
if
utils
.
check_conditional
(
cond
,
self
.
basedir
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
):
if
utils
.
check_conditional
(
cond
,
self
.
basedir
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
):
break
break
if
result
.
result
[
'attempts'
]
==
retries
and
not
utils
.
check_conditional
(
cond
,
self
.
basedir
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
):
if
result
.
result
[
'attempts'
]
==
retries
and
not
utils
.
check_conditional
(
cond
,
self
.
basedir
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
):
result
.
result
[
'failed'
]
=
True
result
.
result
[
'failed'
]
=
True
result
.
result
[
'msg'
]
=
"Task failed as maximum retries was encountered"
result
.
result
[
'msg'
]
=
"Task failed as maximum retries was encountered"
else
:
else
:
result
.
result
[
'attempts'
]
=
0
result
.
result
[
'attempts'
]
=
0
...
@@ -964,6 +968,7 @@ class Runner(object):
...
@@ -964,6 +968,7 @@ class Runner(object):
if
self
.
diff
:
if
self
.
diff
:
self
.
callbacks
.
on_file_diff
(
conn
.
host
,
result
.
diff
)
self
.
callbacks
.
on_file_diff
(
conn
.
host
,
result
.
diff
)
self
.
callbacks
.
on_ok
(
host
,
data
)
self
.
callbacks
.
on_ok
(
host
,
data
)
return
result
return
result
def
_early_needs_tmp_path
(
self
,
module_name
,
handler
):
def
_early_needs_tmp_path
(
self
,
module_name
,
handler
):
...
@@ -988,7 +993,7 @@ class Runner(object):
...
@@ -988,7 +993,7 @@ class Runner(object):
# even when conn has pipelining, old style modules need tmp to store arguments
# even when conn has pipelining, old style modules need tmp to store arguments
return
True
return
True
return
False
return
False
# *****************************************************
# *****************************************************
...
@@ -1107,7 +1112,7 @@ class Runner(object):
...
@@ -1107,7 +1112,7 @@ class Runner(object):
rc
=
conn
.
shell
.
join_path
(
utils
.
last_non_blank_line
(
result
[
'stdout'
])
.
strip
(),
''
)
rc
=
conn
.
shell
.
join_path
(
utils
.
last_non_blank_line
(
result
[
'stdout'
])
.
strip
(),
''
)
# Catch failure conditions, files should never be
# Catch failure conditions, files should never be
# written to locations in /.
# written to locations in /.
if
rc
==
'/'
:
if
rc
==
'/'
:
raise
errors
.
AnsibleError
(
'failed to resolve remote temporary directory from
%
s: `
%
s` returned empty string'
%
(
basetmp
,
cmd
))
raise
errors
.
AnsibleError
(
'failed to resolve remote temporary directory from
%
s: `
%
s` returned empty string'
%
(
basetmp
,
cmd
))
return
rc
return
rc
...
@@ -1131,9 +1136,9 @@ class Runner(object):
...
@@ -1131,9 +1136,9 @@ class Runner(object):
module_data
module_data
)
=
self
.
_configure_module
(
conn
,
module_name
,
module_args
,
inject
,
complex_args
)
)
=
self
.
_configure_module
(
conn
,
module_name
,
module_args
,
inject
,
complex_args
)
module_remote_path
=
conn
.
shell
.
join_path
(
tmp
,
module_name
)
module_remote_path
=
conn
.
shell
.
join_path
(
tmp
,
module_name
)
self
.
_transfer_str
(
conn
,
tmp
,
module_name
,
module_data
)
self
.
_transfer_str
(
conn
,
tmp
,
module_name
,
module_data
)
return
(
module_remote_path
,
module_style
,
module_shebang
)
return
(
module_remote_path
,
module_style
,
module_shebang
)
# *****************************************************
# *****************************************************
...
@@ -1196,7 +1201,7 @@ class Runner(object):
...
@@ -1196,7 +1201,7 @@ class Runner(object):
for
worker
in
workers
:
for
worker
in
workers
:
worker
.
terminate
()
worker
.
terminate
()
worker
.
join
()
worker
.
join
()
results
=
[]
results
=
[]
try
:
try
:
while
not
result_queue
.
empty
():
while
not
result_queue
.
empty
():
...
...
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