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
81e34960
Commit
81e34960
authored
Mar 29, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added preliminary support for --sudo to ansible, playbook support and further testing pending.
parent
011a0ecb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
22 deletions
+14
-22
bin/ansible
+3
-1
bin/ansible-playbook
+0
-1
lib/ansible/connection.py
+10
-17
library/service
+1
-3
No files found.
bin/ansible
View file @
81e34960
...
...
@@ -67,6 +67,8 @@ class Cli(object):
help
=
'condense output'
)
parser
.
add_option
(
'-P'
,
'--poll'
,
default
=
C
.
DEFAULT_POLL_INTERVAL
,
type
=
'int'
,
dest
=
'poll_interval'
,
help
=
'set the poll interval if using -B'
)
parser
.
add_option
(
"-s"
,
"--sudo"
,
default
=
False
,
action
=
"store_true"
,
dest
=
'sudo'
,
help
=
"run operations with sudo (nopasswd)"
)
parser
.
add_option
(
'-t'
,
'--tree'
,
dest
=
'tree'
,
default
=
None
,
help
=
'log output to this directory'
)
parser
.
add_option
(
'-T'
,
'--timeout'
,
default
=
C
.
DEFAULT_TIMEOUT
,
type
=
'int'
,
...
...
@@ -107,7 +109,7 @@ class Cli(object):
host_list
=
options
.
inventory
,
timeout
=
options
.
timeout
,
remote_port
=
options
.
remote_port
,
forks
=
options
.
forks
,
background
=
options
.
seconds
,
pattern
=
pattern
,
callbacks
=
self
.
callbacks
,
verbose
=
True
,
callbacks
=
self
.
callbacks
,
sudo
=
options
.
sudo
,
verbose
=
True
,
)
return
(
runner
,
runner
.
run
())
...
...
bin/ansible-playbook
View file @
81e34960
...
...
@@ -45,7 +45,6 @@ def main(args):
help
=
"run playbook against these hosts regardless of inventory settings"
)
parser
.
add_option
(
'-p'
,
'--port'
,
default
=
C
.
DEFAULT_REMOTE_PORT
,
type
=
'int'
,
dest
=
'remote_port'
,
help
=
'set the remote ssh port'
)
parser
.
add_option
(
'-T'
,
'--timeout'
,
default
=
C
.
DEFAULT_TIMEOUT
,
type
=
'int'
,
dest
=
'timeout'
,
help
=
"set the SSH timeout in seconds"
)
...
...
lib/ansible/connection.py
View file @
81e34960
...
...
@@ -87,17 +87,19 @@ class ParamikoConnection(object):
stdin
,
stdout
,
stderr
=
self
.
ssh
.
exec_command
(
cmd
)
return
(
stdin
,
stdout
,
stderr
)
else
:
# this code is a work in progress, so it's disabled...
self
.
ssh
.
close
()
ssh_sudo
=
self
.
_get_conn
()
sudo_chan
=
ssh_sudo
.
invoke_shell
()
sudo_chan
.
send
(
"sudo -s
\n
"
)
sudo_chan
.
recv
(
1024
)
sudo_chan
.
send
(
"echo &&
%
s && echo
\n
"
%
cmd
)
sudo_chan
.
send
(
"echo 'START==>';
%
s;echo '<==STOP'
\n
"
%
cmd
)
timeout
=
60
# make configurable?
time
.
sleep
(
1
)
while
not
sudo_chan
.
recv_ready
():
# TODO: timeout support
time
.
sleep
(
1
)
out
=
sudo_chan
.
recv
(
1024
)
timeout
-=
1
if
timeout
<
0
:
return
(
None
,
json
.
dumps
(
dict
(
failed
=
True
,
msg
=
"sudo timeout"
)),
''
)
out
=
sudo_chan
.
recv
(
2058
)
sudo_chan
.
close
()
self
.
ssh
=
self
.
_get_conn
()
out
=
self
.
_expect_like
(
out
)
...
...
@@ -105,18 +107,9 @@ class ParamikoConnection(object):
def
_expect_like
(
self
,
msg
):
''' hack to make invoke_shell more or less work for sudo usage '''
lines
=
msg
.
split
(
"
\n
"
)
index
=
0
for
x
in
lines
:
if
x
==
'
\r
'
:
break
index
+=
1
index2
=
index
+
1
for
x
in
lines
[
index
:]:
if
x
==
'
\r
'
:
break
index2
+=
1
return
"
\n
"
.
join
(
lines
[
index
+
1
:
index2
+
1
])
.
strip
()
left
=
msg
.
rindex
(
"START==>"
)
right
=
msg
.
rindex
(
"<==STOP"
)
return
msg
[
left
+
8
:
right
]
.
lstrip
()
.
rstrip
()
def
put_file
(
self
,
in_path
,
out_path
):
''' transfer a file from local to remote '''
...
...
library/service
View file @
81e34960
...
...
@@ -79,9 +79,7 @@ elif state == "restarted":
# run change commands if we need to
def
_run
(
cmd
):
return
subprocess
.
call
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
return
subprocess
.
call
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
rc
=
0
if
changed
:
...
...
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