Skip to content

Instantly share code, notes, and snippets.

@rodesousa
Created March 1, 2016 15:17
Show Gist options
  • Select an option

  • Save rodesousa/59ef9d6ff6b64ecb0188 to your computer and use it in GitHub Desktop.

Select an option

Save rodesousa/59ef9d6ff6b64ecb0188 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import subprocess
import sys
import os
import yaml
import paramiko
import argparse
from paramiko import SSHClient
#init de la connexion
def init_client_ssh():
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
return client
def check_args():
parser = argparse.ArgumentParser(description='script to check environment status')
parser.add_argument('yaml_file', help="yaml file containing environment checks")
return parser
print "------------------------------------"
print "Bienvenue dans Simply Deploy"
print "------------------------------------"
args = check_args().parse_args()
if not os.path.isfile(args.yaml_file):
print'yaml_file not found or Invalid file path'
sys.exit(1)
#yaml
stream = open(args.yaml_file, 'r')
data_yaml = yaml.load(stream)
stream.close()
#conf
stream_config = open('config.yaml')
config = yaml.load(stream_config)
stream_config.close()
#connexion
ssh = init_client_ssh()
ssh.connect(config['server']['hostname'], username=config['server']['user'], password=config['server']['password'])
stdin, stdout, stderr = ssh.exec_command("ls -a")
if data_yaml['repo']['install']:
if data_yaml['install']['type'] == "yum":
cmd = "/opt/seos/bin/sesudo SU- -c \"yum install %s \"" %(data_yaml['install']['app'])
stdin, stdout, stderr = ssh.exec_command(cmd)
error = stderr.readlines()
print ""
if stdout.channel.recv_exit_status() == 0:
print "%s a bien ete installe dans %s" %(data_yaml['install']['app'], config['server']['hostname'])
else:
print "ERREUR ! %s" % error
print "MSG ERREUR ! %s" % stdout.readlines()
else:
print "TODO BIATCH!"
print ""
ssh.close()
print "------------------------------------"
print "Avec Simply Deploy, c'est vraiment simple ;)"
print "------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment