From e879c07d4bb696bc6cffe2009672b409086833c3 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Thu, 3 Sep 2015 12:30:37 +0300 Subject: [PATCH] Address comments to lxc branch and fix several bugs with example-lxc.py - C.HOST_KEY_CHECKING = False for ansible_playbook.py handler - mkdir -p {{keys_dir}} added to ssh_key resource run action --- example-lxc.py | 11 +++++------ resources/ssh_key/actions/run.yml | 8 +++++--- resources/ssh_key/meta.yaml | 7 +++++-- solar/solar/core/handlers/ansible_playbook.py | 5 ++--- solar/solar/core/provider.py | 14 +++++++------- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/example-lxc.py b/example-lxc.py index 91af5a99..6f77ef02 100644 --- a/example-lxc.py +++ b/example-lxc.py @@ -42,8 +42,9 @@ def deploy(): seed = vr.create('nodes', 'templates/seed_node.yml', {})[0] ssh_key = vr.create('ssh_key1', 'resources/ssh_key', { - 'path': '/vagrant/.ssh/id_rsa', - 'pub_path': '/vagrant/.ssh/id_rsa.pub', + 'keys_dir': '/vagrant/.ssh', + 'private_key': '/vagrant/.ssh/id_rsa', + 'public_key': '/vagrant/.ssh/id_rsa.pub', 'passphrase': '', })[0] signals.connect(seed, ssh_key) @@ -100,8 +101,8 @@ def deploy(): signals.connect(lxc_infra1, lxc_host_idx, {'provides': 'requires'}) signals.connect(cnets2, lxc_host_idx) signals.connect(ssh_key, lxc_host_idx, { - 'pub_path': 'pub_key', - 'path': 'user_key'}) + 'public_key': 'pub_key', + 'private_key': 'user_key'}) # RABBIT rabbitmq_service1 = vr.create('rabbitmq_service1', 'resources/rabbitmq_service/', { @@ -134,5 +135,3 @@ main.add_command(deploy) if __name__ == '__main__': main() - -ansible-playbook --module-path /vagrant/library -i /tmp/tmp8bTQzi/tmpGUYX4Bdocker20/inventory /tmp/tmp8bTQzi/tmpGUYX4Bdocker20/runIMUDej \ No newline at end of file diff --git a/resources/ssh_key/actions/run.yml b/resources/ssh_key/actions/run.yml index f8fc1616..11423977 100644 --- a/resources/ssh_key/actions/run.yml +++ b/resources/ssh_key/actions/run.yml @@ -3,10 +3,12 @@ gather_facts: false # this is default variables, they will be overwritten by resource one vars: - path: /vagrant/.ssh/id_rsa + keys_dir: /vagrant/.ssh + private_key: /vagrant/.ssh/id_rsa passphrase: '' tasks: - - stat: path={{path}} + - shell: mkdir -p {{keys_dir}} + - stat: path={{private_key}} register: key - - shell: ssh-keygen -t rsa -f {{path}} -N "" + - shell: ssh-keygen -t rsa -f {{private_key}} -N "" when: key.stat.exists == False diff --git a/resources/ssh_key/meta.yaml b/resources/ssh_key/meta.yaml index ffe71dc1..690764c6 100644 --- a/resources/ssh_key/meta.yaml +++ b/resources/ssh_key/meta.yaml @@ -12,10 +12,13 @@ input: ssh_user: schema: str! value: - path: + keys_dir: schema: str! value: - pub_path: + private_key: + schema: str! + value: + public_key: schema: str! value: passphrase: diff --git a/solar/solar/core/handlers/ansible_playbook.py b/solar/solar/core/handlers/ansible_playbook.py index 992207ec..44ba5964 100644 --- a/solar/solar/core/handlers/ansible_playbook.py +++ b/solar/solar/core/handlers/ansible_playbook.py @@ -21,12 +21,11 @@ class AnsiblePlaybook(base.BaseHandler): def download_roles(self, urls): if not os.path.exists(ROLES_PATH): os.makedirs(ROLES_PATH) - for url in urls: provider = SVNProvider(url) provider.run() fabric_api.local('cp -r {} {}'.format( - provider.repo_directory, ROLES_PATH)) + provider.directory, ROLES_PATH)) def action(self, resource, action): action_file = os.path.join( @@ -48,7 +47,7 @@ class AnsiblePlaybook(base.BaseHandler): else: host = 'localhost' transport = 'local' - + C.HOST_KEY_CHECKING = False play = PlayBook( playbook=action_file, remote_user=remote_user, diff --git a/solar/solar/core/provider.py b/solar/solar/core/provider.py index 1bd569d7..855ce7a7 100644 --- a/solar/solar/core/provider.py +++ b/solar/solar/core/provider.py @@ -115,17 +115,17 @@ class SVNProvider(BaseProvider): 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) + self.repo_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]) + self.repo_directory = self.base_path + self.directory = os.path.join(self.repo_directory, self.url.rsplit('/', 1)[-1]) def run(self): - if not os.path.exists(self.directory): - os.makedirs(self.directory) - if not os.path.exists(self.repo_directory): + os.makedirs(self.repo_directory) + + if not os.path.exists(self.directory): fabric_api.local( 'cd {dir} && svn checkout {url}'.format( - dir=self.directory, + dir=self.repo_directory, url=self.url))