diff --git a/solar/solar/core/handlers/ansible_template.py b/solar/solar/core/handlers/ansible_template.py index 68ebcb4b..9a4507cf 100644 --- a/solar/solar/core/handlers/ansible_template.py +++ b/solar/solar/core/handlers/ansible_template.py @@ -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) diff --git a/solar/solar/core/handlers/base.py b/solar/solar/core/handlers/base.py index df25e6f0..aa44ae0a 100644 --- a/solar/solar/core/handlers/base.py +++ b/solar/solar/core/handlers/base.py @@ -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)