Permalink
Browse files

Merge branch 'develop' of github.com:Proteus-tech/deploy into develop

  • Loading branch information...
2 parents 333ed00 + d0d6d98 commit 727c30cf67dffeccd7099957c4bbb8be424ddb3b siraset committed May 29, 2012
Showing with 27 additions and 0 deletions.
  1. +27 −0 proteus/put_private_key_to_server.py
@@ -0,0 +1,27 @@
+from fabric.api import local, settings
+from fabric.contrib.files import exists
+from fabric.operations import run, sudo
+from profab.role import Role
+from proteus.authorize_key import authorize_key
+
+def put_private_key_to_server(server, current_user):
+ current_home = '/home/%s' % current_user
+ private_key = local('cat ~/.ssh/id_rsa', capture=True)
+
+ if not exists('%s/.ssh/' % current_home):
+ sudo('mkdir %s/.ssh/' % current_home, user=current_user)
+ if not exists('%s/.ssh/id_rsa' % current_home):
+ sudo('echo "%s" >> %s/.ssh/id_rsa' % (private_key, current_home), user=current_user)
+ sudo('chmod 600 %s/.ssh/id_rsa' % current_home, user=current_user)
+
+
+class Configure(Role):
+ """
+ Role to put private key to target server
+ Parameter
+ - target_server's current_user
+ """
+ def configure(self, server):
+ current_user = self.parameter
+ put_private_key_to_server(server, current_user)
+

0 comments on commit 727c30c

Please sign in to comment.