from modules.pastafari2.libraries.task import Task from modules.pastafari2.models.pastafari2 import ServerDbTask import os class ServerTask(Task): def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}): super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data) #self.files=[['modules/pastafari2/scripts/system/alive.sh', 0o755]] self.files=[['modules/pastafari2/scripts/system/change_password.py', 0o755]] #self.files.append([self.data['ssh_pub_key'], 0o600]) self.commands_to_execute=[] #self.commands_to_execute.append(['modules/pastafari2/scripts/system/alive.sh', '']) #self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_pzoo_stats.py', '--user='+self.data['ssh_user']+' --pub_key='+self.data['pub_key']+' --url_stats='+self.data['url_stats']+' --group="'+self.data['group_name']+'" --path='+remote_path]) def pre_task(self): ssh_pub_key_file='' final_ssh_pub='' if self.data['ssh_pub_key']!='': with open('./modules/webservers/scripts/files/id_rsa.pub', 'w') as f: f.write(self.data['ssh_pub_key']) ssh_pub_key_file='./modules/webservers/scripts/files/id_rsa.pub' self.files.append([ssh_pub_key_file, 0o600]) final_ssh_pub='--ssh_pub_key_file="'+ssh_pub_key_file+'"' final_password='' if self.data['password']!='': final_password='--password=%s' % self.data['password'] self.commands_to_execute.append(['modules/pastafari2/scripts/system/change_password.py', '--user=%s %s %s' % (self.data['user'], final_password, final_ssh_pub), 'sudo']) return True """ def post_task(self): if os.path.isfile('./modules/webservers/scripts/files/id_rsa.pub'): return True """