Merge pull request #264 from pigmej/different_local_and_remote_paths

Remote and Local temp paths are different
This commit is contained in:
Łukasz Oleś 2015-10-19 18:56:04 +02:00
commit 07c10e6a22
2 changed files with 21 additions and 3 deletions

View File

@ -17,7 +17,7 @@ from fabric.state import env
import os
from solar.core.log import log
from solar.core.handlers.base import TempFileHandler
from solar.core.handlers.base import TempFileHandler, SOLAR_TEMP_LOCAL_LOCATION
from solar import errors
# otherwise fabric will sys.exit(1) in case of errors
@ -41,7 +41,11 @@ class AnsibleTemplate(TempFileHandler):
self.transport_sync.copy(resource, '/vagrant/library', '/tmp')
self.transport_sync.sync_all()
call_args = ['ansible-playbook', '--module-path', '/tmp/library', '-i', inventory_file, playbook_file]
# remote paths are not nested inside solar_local
remote_playbook_file = playbook_file.replace(SOLAR_TEMP_LOCAL_LOCATION, '/tmp/')
remote_inventory_file = inventory_file.replace(SOLAR_TEMP_LOCAL_LOCATION, '/tmp/')
call_args = ['ansible-playbook', '--module-path', '/tmp/library', '-i', remote_inventory_file, remote_playbook_file]
log.debug('EXECUTING: %s', ' '.join(call_args))
out = self.transport_run.run(resource, *call_args)

View File

@ -16,6 +16,7 @@
import os
import shutil
import tempfile
import errno
from jinja2 import Template
@ -23,6 +24,11 @@ from solar.core.log import log
from solar.core.transports.ssh import SSHSyncTransport, SSHRunTransport
tempfile.gettempdir()
SOLAR_TEMP_LOCAL_LOCATION = os.path.join(tempfile.tempdir, 'solar_local')
class BaseHandler(object):
def __init__(self, resources, handlers=None):
@ -46,9 +52,17 @@ class BaseHandler(object):
class TempFileHandler(BaseHandler):
def __init__(self, resources, handlers=None):
super(TempFileHandler, self).__init__(resources, handlers)
self.dst = tempfile.mkdtemp()
self.dst = None
def __enter__(self):
try:
self.dst = tempfile.mkdtemp(dir=SOLAR_TEMP_LOCAL_LOCATION)
except OSError as ex:
if ex.errno == errno.ENOENT:
os.makedirs(SOLAR_TEMP_LOCAL_LOCATION)
self.dst = tempfile.mkdtemp(dir=SOLAR_TEMP_LOCAL_LOCATION)
else:
raise
self.dirs = {}
for resource in self.resources:
resource_dir = tempfile.mkdtemp(suffix=resource.name, dir=self.dst)