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
1e860ba1
Commit
1e860ba1
authored
Feb 27, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #39 from skvidal/master
make tmp path be a dir rather than a temp file
parents
8fc69d30
39f42cfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
lib/ansible/runner.py
+12
-8
library/command
+6
-0
No files found.
lib/ansible/runner.py
View file @
1e860ba1
...
...
@@ -76,6 +76,7 @@ class Runner(object):
self
.
verbose
=
verbose
self
.
remote_user
=
remote_user
self
.
remote_pass
=
remote_pass
self
.
_tmp_paths
=
{}
def
_parse_hosts
(
self
,
host_list
):
''' parse the host inventory file if not sent as an array '''
...
...
@@ -189,7 +190,8 @@ class Runner(object):
dest
=
options
[
'dest'
]
# transfer the file to a remote tmp location
tmp_src
=
self
.
_get_tmp_path
(
conn
,
dest
.
split
(
"/"
)[
-
1
])
tmp_path
=
self
.
_get_tmp_path
(
conn
)
tmp_src
=
tmp_path
+
source
.
split
(
'/'
)[
-
1
]
self
.
_transfer_file
(
conn
,
source
,
tmp_src
)
# install the copy module
...
...
@@ -213,7 +215,7 @@ class Runner(object):
# first copy the source template over
tempname
=
os
.
path
.
split
(
source
)[
-
1
]
temppath
=
self
.
_get_tmp_path
(
conn
,
tempname
)
temppath
=
self
.
_get_tmp_path
(
conn
)
+
tempname
self
.
_transfer_file
(
conn
,
source
,
temppath
)
# install the template module
...
...
@@ -261,7 +263,6 @@ class Runner(object):
def
remote_log
(
self
,
conn
,
msg
):
''' this is the function we use to log things '''
stdin
,
stdout
,
stderr
=
conn
.
exec_command
(
'/usr/bin/logger -t ansible -p auth.info
%
r'
%
msg
)
# TODO: doesn't actually call logger on the remote box, should though
# TODO: maybe make that optional
def
_exec_command
(
self
,
conn
,
cmd
):
...
...
@@ -272,18 +273,21 @@ class Runner(object):
results
=
"
\n
"
.
join
(
stdout
.
readlines
())
return
results
def
_get_tmp_path
(
self
,
conn
,
file_name
):
def
_get_tmp_path
(
self
,
conn
):
''' gets a temporary path on a remote box '''
output
=
self
.
_exec_command
(
conn
,
"mktemp /tmp/
%
s.XXXXXX"
%
file_name
)
return
output
.
split
(
"
\n
"
)[
0
]
if
conn
not
in
self
.
_tmp_paths
:
output
=
self
.
_exec_command
(
conn
,
"mktemp -d /tmp/ansible.XXXXXX"
)
self
.
_tmp_paths
[
conn
]
=
output
.
split
(
"
\n
"
)[
0
]
+
'/'
return
self
.
_tmp_paths
[
conn
]
def
_copy_module
(
self
,
conn
):
''' transfer a module over SFTP, does not run it '''
in_path
=
os
.
path
.
expanduser
(
os
.
path
.
join
(
self
.
module_path
,
self
.
module_name
)
)
out_path
=
self
.
_get_tmp_path
(
conn
,
"ansible_
%
s"
%
self
.
module_name
)
out_path
=
self
.
_get_tmp_path
(
conn
)
+
self
.
module_name
sftp
=
conn
.
open_sftp
()
sftp
.
put
(
in_path
,
out_path
)
sftp
.
close
()
...
...
library/command
View file @
1e860ba1
...
...
@@ -17,6 +17,12 @@ try:
cmd
=
subprocess
.
Popen
(
args
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
except
(
OSError
,
IOError
),
e
:
print
json
.
dumps
({
"failed"
:
1
,
"error"
:
str
(
e
),
})
sys
.
exit
(
1
)
except
:
print
json
.
dumps
({
"failed"
:
1
,
...
...
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