Ejemplo n.º 1
0
def clean_ca(hostname):
    '''
        清理CA
    '''
    ca_server = '10.134.33.223'
    ca_pass = '******'
    root_user = '******'

    cmd = "puppet cert -c %s" % hostname
    deal_ssh.remote_ssh_password_simple(ca_server,root_user,ca_pass,cmd)
Ejemplo n.º 2
0
def set_password(ip):
    '''
        修改密码
    '''
    import random
    def id_generator(size=6, chars=string.ascii_uppercase + string.digits+'&%+-()'):
        return ''.join(random.choice(chars) for _ in range(size))

    new_password = id_generator(14)
    user = "******"
    host  = ip 

    command = '''str=$((echo \"%s\";echo \"%s\")|sudo /sbin/grub-md5-crypt 2>/dev/null | grep -iv \"password\");sudo cat /etc/shadow | awk -v str=$str -F ':' '{OFS=":"}{if($1~/root/){sub(/.*/,str,$2);}print }' > ~/shadow;sudo /bin/cp -f ~/shadow /etc/shadow;sudo chown root:root /etc/shadow;sudo chmod 400 /etc/shadow;rm -f ~/shadow''' % (new_password,new_password) 


    f = open("/tmp/machine.list.pass","a+")
    f.write(ip)
    f.write(" ")
    f.write(new_password)
    f.write("\n")
    result = deal_ssh.remote_ssh_key_exec_simple(host,user,command)
    
    if result:
        pass
    else:
        print "%s failed" % ip
        

    cmd = "ls"
    root_user = "******"
    if deal_ssh.remote_ssh_password_simple(host,root_user,new_password,cmd):
        pass
    else:
        print "host: %s, exec failed!" % ip
Ejemplo n.º 3
0
def close_host_config(puppet_list):
    result = ""
    log_time = time.strftime("%Y_%m_%d",time.localtime())
    for serverinfo in puppet_list:
        server_ip = serverinfo['puppet_server_ip']
        remote_user = serverinfo['puppet_server_user']
        remote_pass = serverinfo['puppet_server_passwd']

        command = "mv /etc/puppet/manifests/site.pp /tmp/site.pp.%s;mv /etc/puppet/manifests/site.pp.BAK /etc/puppet/manifests/site.pp;" % log_time

        result = deal_ssh.remote_ssh_password_simple(server_ip,remote_user,remote_pass,command)
        if result:
            print "puppet server %s: delete sucess!" % server_ip
Ejemplo n.º 4
0
def check_default_password(ip):
    '''
        检查默认密码
    '''
    import random
    def id_generator(size=6, chars=string.ascii_uppercase + string.digits+'@#$%^&*()'):
        return ''.join(random.choice(chars) for _ in range(size))

    new_password = id_generator(14)


    user = "******"
    #cmd = "ifconfig eth0 | grep \"inet addr\" | cut -d \":\" -f2"
    _command = 'echo \'%s\' | passwd %s --stdin' % (new_password,user)
    host  = ip 
    user  = "******"
    passwd  = "noSafeNoWork@2014"
    try:
        deal_ssh.remote_ssh_password_simple(host,user,passwd,_command)
    except Exception,e:
        print e
        return False
Ejemplo n.º 5
0
    def set_host_config(self,web_puppet_conf,default_puppet_conf,puppet_list):
        '''
            设置puppet配置在puppet server上面
        '''
        result = ""
        for serverinfo in puppet_list:
            server_ip = serverinfo['puppet_server_ip']
            remote_user = serverinfo['puppet_server_user']
            remote_pass = serverinfo['puppet_server_passwd']

            command = "mv /etc/puppet/manifests/site.pp /etc/puppet/manifests/site.pp.BAK;echo %s > /etc/puppet/manifests/site.pp;echo %s >> etc/puppet/manifests/site.pp" % (web_puppet_conf,default_puppet_conf)

            result = deal_ssh.remote_ssh_password_simple(server_ip,remote_user,remote_pass,command)
            if result:
                print "puppet server %s: update sucess!" % server_ip
Ejemplo n.º 6
0
def check_passwd(ip,new_password):
    #os.popen("mv /root/.ssh /root/.ssh.BAK")
    cmd = "ls"
    root_user = "******"
    if deal_ssh.remote_ssh_password_simple(ip,root_user,new_password,cmd):
        print "host: %s, exec ok!" % ip
        return True
    else:
        print "host: %s, exec failed!" % ip
        f = open ("/tmp/error.ip",'a+')
        f.write("%s" % ip)
        f.write("\n")
        f.close()
        print "host: %s, exec failed!" % ip
        return False
Ejemplo n.º 7
0
def change_dir(host,new_password):
    user = "******"
    # cmd = "sudo userdel -r fangxiuli;groupdel fangxiuli;\
    # sudo userdel -r liujunjie;groupdel liujunjie;\
    # sudo userdel -r gubozhi;groupdel gubozhi;\
    # sudo userdel -r shanhongjie;groupdel shanhongjie;\
    # sudo userdel -r shanhongjie;groupdel shanhongjie;\
    # sudo userdel -r wangshuo;groupdel wangshuo;\
    # sudo userdel -r yanghuihui;groupdel yanghuihui;\
    # sudo userdel -r zhongtingting;groupdel zhongtingting;"
    #cmd = "umount /search;sed -i s/search/data/g /etc/fstab;mkdir /data ; mount -a;df -h"
    #cmd = "cat /etc/passwd | grep \"for_monitor\""
    #cmd = "sed '/tc_202_117/d' ~/.ssh/authorized_keys"
    #cmd = "cat /etc/passwd | awk -F \":\" '{print $1}' |grep -E \"for_dev|for_monitor|lixuebin|for_ct|biztech|liyangshao|lizhi|wujuefei|heguanghao|yuchang|wangshuai|wangwei|dongyuntao|zhangchengshan|gaozezhou\""
    cmd = "echo \"noSafeNoWork@2014\" | passwd --stdin root"
    result = deal_ssh.remote_ssh_password_simple(host,user,new_password,cmd)

    if isinstance(result,bool):
        print ip," au failed"
Ejemplo n.º 8
0

    user = "******"
    #cmd = "ifconfig eth0 | grep \"inet addr\" | cut -d \":\" -f2"
    _command = 'echo \'%s\' | passwd %s --stdin' % (new_password,user)
    host  = ip 
    user  = "******"
    passwd  = "noSafeNoWork@2014"
    try:
        deal_ssh.remote_ssh_password_simple(host,user,passwd,_command)
    except Exception,e:
        print e
        return False
    else:
        cmd = "hostname -f"
        if  deal_ssh.remote_ssh_password_simple(host,user,new_password,cmd):
            f = open('/tmp/machine.list.pass2','a+')
            f.write(ip)
            f.write(",")
            f.write(new_password)
            f.write("\n")
            f.close()
            return True
        else:
            print ip

def check_passwd(ip,new_password):
    #os.popen("mv /root/.ssh /root/.ssh.BAK")
    cmd = "ls"
    root_user = "******"
    if deal_ssh.remote_ssh_password_simple(ip,root_user,new_password,cmd):