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
7c65f3dd
Commit
7c65f3dd
authored
Jun 18, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
partial become support for local connection plugin
parent
671118ba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
32 deletions
+28
-32
lib/ansible/plugins/connections/local.py
+28
-32
No files found.
lib/ansible/plugins/connections/local.py
View file @
7c65f3dd
...
...
@@ -22,8 +22,8 @@ import traceback
import
os
import
shutil
import
subprocess
#
import select
#
import fcntl
import
select
import
fcntl
import
ansible.constants
as
C
...
...
@@ -51,18 +51,17 @@ class Connection(ConnectionBase):
def
exec_command
(
self
,
cmd
,
tmp_path
,
in_data
=
None
,
sudoable
=
True
):
''' run a command on the local host '''
super
(
Connection
,
self
)
.
exec_command
(
cmd
,
tmp_path
,
in_data
=
in_data
)
super
(
Connection
,
self
)
.
exec_command
(
cmd
,
tmp_path
,
in_data
=
in_data
,
sudoable
=
sudoable
)
debug
(
"in local.exec_command()"
)
# su requires to be run from a terminal, and therefore isn't supported here (yet?)
#if self._connection_info.su:
# raise AnsibleError("Internal Error: this module does not support running commands via su")
if
in_data
:
raise
AnsibleError
(
"Internal Error: this module does not support optimized module pipelining"
)
executable
=
C
.
DEFAULT_EXECUTABLE
.
split
()[
0
]
if
C
.
DEFAULT_EXECUTABLE
else
None
if
sudoable
:
cmd
,
self
.
prompt
,
self
.
success_key
=
self
.
_connection_info
.
make_become_cmd
(
cmd
)
self
.
_display
.
vvv
(
"{0} EXEC {1}"
.
format
(
self
.
_connection_info
.
remote_addr
,
cmd
))
# FIXME: cwd= needs to be set to the basedir of the playbook
debug
(
"opening command with Popen()"
)
...
...
@@ -76,31 +75,28 @@ class Connection(ConnectionBase):
)
debug
(
"done running command with Popen()"
)
# FIXME: more su/sudo stuff
#if self.runner.sudo and sudoable and self.runner.sudo_pass:
# fcntl.fcntl(p.stdout, fcntl.F_SETFL,
# fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK)
# fcntl.fcntl(p.stderr, fcntl.F_SETFL,
# fcntl.fcntl(p.stderr, fcntl.F_GETFL) | os.O_NONBLOCK)
# sudo_output = ''
# while not sudo_output.endswith(prompt) and success_key not in sudo_output:
# rfd, wfd, efd = select.select([p.stdout, p.stderr], [],
# [p.stdout, p.stderr], self.runner.timeout)
# if p.stdout in rfd:
# chunk = p.stdout.read()
# elif p.stderr in rfd:
# chunk = p.stderr.read()
# else:
# stdout, stderr = p.communicate()
# raise AnsibleError('timeout waiting for sudo password prompt:\n' + sudo_output)
# if not chunk:
# stdout, stderr = p.communicate()
# raise AnsibleError('sudo output closed while waiting for password prompt:\n' + sudo_output)
# sudo_output += chunk
# if success_key not in sudo_output:
# p.stdin.write(self.runner.sudo_pass + '\n')
# fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK)
# fcntl.fcntl(p.stderr, fcntl.F_SETFL, fcntl.fcntl(p.stderr, fcntl.F_GETFL) & ~os.O_NONBLOCK)
if
self
.
prompt
:
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_GETFL
)
|
os
.
O_NONBLOCK
)
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_GETFL
)
|
os
.
O_NONBLOCK
)
become_output
=
''
while
not
self
.
check_become_success
(
become_output
)
and
not
self
.
check_password_prompt
(
become_output
):
rfd
,
wfd
,
efd
=
select
.
select
([
p
.
stdout
,
p
.
stderr
],
[],
[
p
.
stdout
,
p
.
stderr
],
self
.
_connection_info
.
timeout
)
if
p
.
stdout
in
rfd
:
chunk
=
p
.
stdout
.
read
()
elif
p
.
stderr
in
rfd
:
chunk
=
p
.
stderr
.
read
()
else
:
stdout
,
stderr
=
p
.
communicate
()
raise
AnsibleError
(
'timeout waiting for privilege escalation password prompt:
\n
'
+
become_output
)
if
not
chunk
:
stdout
,
stderr
=
p
.
communicate
()
raise
AnsibleError
(
'privilege output closed while waiting for password prompt:
\n
'
+
become_output
)
become_output
+=
chunk
if
not
self
.
check_become_success
(
become_output
):
p
.
stdin
.
write
(
self
.
_connection_info
.
become_pass
+
'
\n
'
)
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_GETFL
)
&
~
os
.
O_NONBLOCK
)
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_GETFL
)
&
~
os
.
O_NONBLOCK
)
debug
(
"getting output with communicate()"
)
stdout
,
stderr
=
p
.
communicate
()
...
...
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