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
888bcd65
Commit
888bcd65
authored
Sep 30, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create error messages instead of tracebacks.
parent
946c5665
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
lib/ansible/plugins/connection/docker.py
+19
-11
No files found.
lib/ansible/plugins/connection/docker.py
View file @
888bcd65
...
...
@@ -3,6 +3,7 @@
# Connection plugin for configuring docker containers
# (c) 2014, Lorin Hochstein
# (c) 2015, Leendert Brouwer
# (c) 2015, Toshio Kuratomi <tkuratomi@ansible.com>
#
# Maintainer: Leendert Brouwer (https://github.com/objectified)
#
...
...
@@ -20,7 +21,10 @@
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
import
distutils.spawn
import
os
import
subprocess
import
re
...
...
@@ -36,8 +40,8 @@ BUFSIZE = 65536
class
Connection
(
ConnectionBase
):
has_pipelining
=
True
transport
=
'docker'
has_pipelining
=
True
# su currently has an undiagnosed issue with calculating the file
# checksums (so copy, for instance, doesn't work right)
# Have to look into that before re-enabling this
...
...
@@ -52,10 +56,13 @@ class Connection(ConnectionBase):
# group). But if the user is getting a permission denied error it
# probably means that docker on their system is only configured to be
# connected to by root and they are not running as root.
if
'docker_command'
in
kwargs
:
self
.
docker_cmd
=
kwargs
[
'docker_command'
]
else
:
self
.
docker_cmd
=
'docker'
self
.
docker_cmd
=
distutils
.
spawn
.
find_executable
(
'docker'
)
if
not
self
.
docker_cmd
:
raise
AnsibleError
(
"docker command not found in PATH"
)
self
.
can_copy_bothways
=
False
...
...
@@ -93,7 +100,7 @@ class Connection(ConnectionBase):
""" Connect to the container. Nothing to do """
super
(
Connection
,
self
)
.
_connect
()
if
not
self
.
_connected
:
self
.
_display
.
vvv
(
"ESTABLISH
LOCAL
CONNECTION FOR USER: {0}"
.
format
(
self
.
_display
.
vvv
(
"ESTABLISH
DOCKER
CONNECTION FOR USER: {0}"
.
format
(
self
.
_play_context
.
remote_user
,
host
=
self
.
_play_context
.
remote_addr
)
)
self
.
_connected
=
True
...
...
@@ -107,6 +114,8 @@ class Connection(ConnectionBase):
local_cmd
=
[
self
.
docker_cmd
,
"exec"
,
'-i'
,
self
.
_play_context
.
remote_addr
,
executable
,
'-c'
,
cmd
]
self
.
_display
.
vvv
(
"EXEC
%
s"
%
(
local_cmd
),
host
=
self
.
_play_context
.
remote_addr
)
# FIXME: cwd= needs to be set to the basedir of the playbook, which
# should come from loader, but is not in the connection plugins
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
False
,
stdin
=
subprocess
.
PIPE
,
...
...
@@ -127,13 +136,11 @@ class Connection(ConnectionBase):
if
self
.
can_copy_bothways
:
# only docker >= 1.8.1 can do this natively
args
=
[
self
.
docker_cmd
,
"cp"
,
"
%
s"
%
in_path
,
"
%
s:
%
s"
%
(
self
.
_play_context
.
remote_addr
,
out_path
)
]
subprocess
.
check_call
(
args
)
args
=
[
self
.
docker_cmd
,
"cp"
,
in_path
,
"
%
s:
%
s"
%
(
self
.
_play_context
.
remote_addr
,
out_path
)
]
p
=
subprocess
.
Popen
(
args
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
()
if
p
.
returncode
!=
0
:
raise
AnsibleError
(
"failed to transfer file
%
s to
%
s:
\n
%
s
\n
%
s"
%
(
in_path
,
out_path
,
stdout
,
stderr
))
else
:
# Older docker doesn't have native support for copying files into
# running containers, so we use docker exec to implement this
...
...
@@ -145,7 +152,7 @@ class Connection(ConnectionBase):
p
=
subprocess
.
Popen
(
args
,
stdin
=
in_file
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
except
OSError
:
raise
AnsibleError
(
"docker connection requires dd command in the chroot"
)
raise
AnsibleError
(
"docker connection
with docker < 1.8.1
requires dd command in the chroot"
)
stdout
,
stderr
=
p
.
communicate
()
if
p
.
returncode
!=
0
:
...
...
@@ -174,4 +181,5 @@ class Connection(ConnectionBase):
def
close
(
self
):
""" Terminate the connection. Nothing to do for Docker"""
super
(
Connection
,
self
)
.
close
()
self
.
_connected
=
False
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