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
0441a7a2
Commit
0441a7a2
authored
Aug 26, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finishing off porting of chroot connection plugin
parent
017bd7b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
lib/ansible/plugins/connections/chroot.py
+18
-11
No files found.
lib/ansible/plugins/connections/chroot.py
View file @
0441a7a2
...
@@ -20,14 +20,16 @@ from __future__ import (absolute_import, division, print_function)
...
@@ -20,14 +20,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__
=
type
__metaclass__
=
type
import
distutils.spawn
import
distutils.spawn
import
traceback
import
os
import
os
import
shlex
import
shlex
import
subprocess
import
subprocess
import
traceback
from
ansible
import
constants
as
C
from
ansible.errors
import
AnsibleError
from
ansible.errors
import
AnsibleError
from
ansible
import
utils
from
ansible.plugins.connections
import
ConnectionBase
from
ansible.utils.path
import
is_executable
from
ansible.utils.unicode
import
to_bytes
from
ansible.utils.unicode
import
to_bytes
import
ansible.constants
as
C
class
Connection
(
ConnectionBase
):
class
Connection
(
ConnectionBase
):
...
@@ -51,13 +53,17 @@ class Connection(ConnectionBase):
...
@@ -51,13 +53,17 @@ class Connection(ConnectionBase):
raise
AnsibleError
(
"
%
s is not a directory"
%
self
.
chroot
)
raise
AnsibleError
(
"
%
s is not a directory"
%
self
.
chroot
)
chrootsh
=
os
.
path
.
join
(
self
.
chroot
,
'bin/sh'
)
chrootsh
=
os
.
path
.
join
(
self
.
chroot
,
'bin/sh'
)
if
not
utils
.
is_executable
(
chrootsh
):
if
not
is_executable
(
chrootsh
):
raise
AnsibleError
(
"
%
s does not look like a chrootable dir (/bin/sh missing)"
%
self
.
chroot
)
raise
AnsibleError
(
"
%
s does not look like a chrootable dir (/bin/sh missing)"
%
self
.
chroot
)
self
.
chroot_cmd
=
distutils
.
spawn
.
find_executable
(
'chroot'
)
self
.
chroot_cmd
=
distutils
.
spawn
.
find_executable
(
'chroot'
)
if
not
self
.
chroot_cmd
:
if
not
self
.
chroot_cmd
:
raise
AnsibleError
(
"chroot command not found in PATH"
)
raise
AnsibleError
(
"chroot command not found in PATH"
)
@property
def
transport
(
self
):
''' used to identify this connection object '''
return
'chroot'
def
_connect
(
self
,
port
=
None
):
def
_connect
(
self
,
port
=
None
):
''' connect to the chroot; nothing to do here '''
''' connect to the chroot; nothing to do here '''
...
@@ -86,8 +92,8 @@ class Connection(ConnectionBase):
...
@@ -86,8 +92,8 @@ class Connection(ConnectionBase):
return the process's exit code immediately.
return the process's exit code immediately.
'''
'''
if
sudoable
and
self
.
runner
.
become
and
self
.
runner
.
become_method
not
in
self
.
become_methods_supported
:
if
sudoable
and
self
.
_play_context
.
become
and
self
.
_play_context
.
become_method
not
in
self
.
become_methods_supported
:
raise
AnsibleError
(
"Internal Error: this module does not support running commands via
%
s"
%
self
.
runner
.
become_method
)
raise
AnsibleError
(
"Internal Error: this module does not support running commands via
%
s"
%
self
.
_play_context
.
become_method
)
if
in_data
:
if
in_data
:
raise
AnsibleError
(
"Internal Error: this module does not support optimized module pipelining"
)
raise
AnsibleError
(
"Internal Error: this module does not support optimized module pipelining"
)
...
@@ -96,8 +102,9 @@ class Connection(ConnectionBase):
...
@@ -96,8 +102,9 @@ class Connection(ConnectionBase):
local_cmd
=
self
.
_generate_cmd
(
executable
,
cmd
)
local_cmd
=
self
.
_generate_cmd
(
executable
,
cmd
)
self
.
_display
.
vvv
(
"EXEC
%
s"
%
(
local_cmd
),
host
=
self
.
chroot
)
self
.
_display
.
vvv
(
"EXEC
%
s"
%
(
local_cmd
),
host
=
self
.
chroot
)
# 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
,
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
False
,
cwd
=
self
.
runner
.
basedir
,
stdin
=
stdin
,
stdin
=
stdin
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
...
@@ -119,7 +126,7 @@ class Connection(ConnectionBase):
...
@@ -119,7 +126,7 @@ class Connection(ConnectionBase):
try
:
try
:
with
open
(
in_path
,
'rb'
)
as
in_file
:
with
open
(
in_path
,
'rb'
)
as
in_file
:
try
:
try
:
p
=
self
.
_buffered_exec_command
(
'dd of=
%
s bs=
%
s'
%
(
out_path
,
BUFSIZE
),
None
,
stdin
=
in_file
)
p
=
self
.
_buffered_exec_command
(
'dd of=
%
s bs=
%
s'
%
(
out_path
,
self
.
BUFSIZE
),
None
,
stdin
=
in_file
)
except
OSError
:
except
OSError
:
raise
AnsibleError
(
"chroot connection requires dd command in the chroot"
)
raise
AnsibleError
(
"chroot connection requires dd command in the chroot"
)
try
:
try
:
...
@@ -138,16 +145,16 @@ class Connection(ConnectionBase):
...
@@ -138,16 +145,16 @@ class Connection(ConnectionBase):
self
.
_display
.
vvv
(
"FETCH
%
s TO
%
s"
%
(
in_path
,
out_path
),
host
=
self
.
chroot
)
self
.
_display
.
vvv
(
"FETCH
%
s TO
%
s"
%
(
in_path
,
out_path
),
host
=
self
.
chroot
)
try
:
try
:
p
=
self
.
_buffered_exec_command
(
'dd if=
%
s bs=
%
s'
%
(
in_path
,
BUFSIZE
),
None
)
p
=
self
.
_buffered_exec_command
(
'dd if=
%
s bs=
%
s'
%
(
in_path
,
self
.
BUFSIZE
),
None
)
except
OSError
:
except
OSError
:
raise
AnsibleError
(
"chroot connection requires dd command in the chroot"
)
raise
AnsibleError
(
"chroot connection requires dd command in the chroot"
)
with
open
(
out_path
,
'wb+'
)
as
out_file
:
with
open
(
out_path
,
'wb+'
)
as
out_file
:
try
:
try
:
chunk
=
p
.
stdout
.
read
(
BUFSIZE
)
chunk
=
p
.
stdout
.
read
(
self
.
BUFSIZE
)
while
chunk
:
while
chunk
:
out_file
.
write
(
chunk
)
out_file
.
write
(
chunk
)
chunk
=
p
.
stdout
.
read
(
BUFSIZE
)
chunk
=
p
.
stdout
.
read
(
self
.
BUFSIZE
)
except
:
except
:
traceback
.
print_exc
()
traceback
.
print_exc
()
raise
AnsibleError
(
"failed to transfer file
%
s to
%
s"
%
(
in_path
,
out_path
))
raise
AnsibleError
(
"failed to transfer file
%
s to
%
s"
%
(
in_path
,
out_path
))
...
...
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