diff --git a/solar/requirements.txt b/solar/requirements.txt index 1896bfa0..c4288753 100644 --- a/solar/requirements.txt +++ b/solar/requirements.txt @@ -16,3 +16,4 @@ Fabric==1.10.2 tabulate==0.7.5 ansible celery +mock diff --git a/solar/solar/core/handlers/ansible_playbook.py b/solar/solar/core/handlers/ansible_playbook.py index 6eed64ef..992207ec 100644 --- a/solar/solar/core/handlers/ansible_playbook.py +++ b/solar/solar/core/handlers/ansible_playbook.py @@ -6,17 +6,27 @@ from ansible.playbook import PlayBook from ansible import utils from ansible import callbacks import ansible.constants as C +from fabric import api as fabric_api from solar.core.handlers import base from solar import errors from solar.core.provider import SVNProvider +ROLES_PATH = '/etc/ansible/roles' + + class AnsiblePlaybook(base.BaseHandler): def download_roles(self, urls): + if not os.path.exists(ROLES_PATH): + os.makedirs(ROLES_PATH) + for url in urls: - SVNProvider(url, '/etc/ansible/roles').run() + provider = SVNProvider(url) + provider.run() + fabric_api.local('cp -r {} {}'.format( + provider.repo_directory, ROLES_PATH)) def action(self, resource, action): action_file = os.path.join( diff --git a/solar/solar/core/provider.py b/solar/solar/core/provider.py index 6fff07b3..1bd569d7 100644 --- a/solar/solar/core/provider.py +++ b/solar/solar/core/provider.py @@ -110,16 +110,22 @@ class SVNProvider(BaseProvider): but with svn you can """ - def __init__(self, url, path='.'): + def __init__(self, url, path='.', base_path=None): self.url = url self.path = path + self.base_path = base_path or utils.read_config()['resources-directory'] + if path != '.': + self.directory = os.path.join(self.base_path, path) + else: + self.directory = self.base_path + self.repo_directory = os.path.join(self.directory, self.url.rsplit('/', 1)[-1]) def run(self): - if not os.path.exists(self.path): - os.makedirs(self.path) - full_path_role = os.path.join(self.path, self.url.rsplit('/', 1)[-1]) - if not os.path.exists(full_path_role): + if not os.path.exists(self.directory): + os.makedirs(self.directory) + + if not os.path.exists(self.repo_directory): fabric_api.local( - 'cd {path} && svn checkout {url}'.format( - path=self.path, + 'cd {dir} && svn checkout {url}'.format( + dir=self.directory, url=self.url))