zoukankan      html  css  js  c++  java
  • # fabirc 配置多组服务器 密码与密钥一起使用 key_filename的设置

    环境说明

    myv myv2 是配置在/etc/hosts 的两台 虚拟机 虚拟机ip.

    参考英文文档

    官方文档的例子不是给的很详细..
    http://docs.fabfile.org/en/1.13/usage/env.html

    实例

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    from fabric.api import *
    
    #只有 student@myv2 这个机器用的是密码
    env.hosts = ['gsx@myv','student@myv2','gsx@myv2']
    
    
    # This dictionary is largely for internal use, and is filled automatically as a per-host-string password cache. Keys are full host strings and values are passwords (strings).
    env.passwords = {
            'student@myv2:22':'1',
    }
    
    
    # http://docs.fabfile.org/en/1.13/usage/env.html
    # May be a string or list of strings, referencing file paths to SSH key files to try when connecting. Passed through directly to the SSH layer. May be set/appended to with -i.
    env.key_filename = ['~/.ssh/test','~/.ssh/test8']
    
    def remoteRun():
        print "ENV %s" %(env.hosts)
        out = run('whoami')
        print "Output %s"%(out)
    
    @hosts('gsx@myv2','gsx@myv')
    def taskSelectHost():
        run('ifconfig')
    
    

    测试执行

    fab -f ./multi_user_and_secret.py  remoteRun taskSelectHost
    

    说明

    密码的填写 evn.passwords

    student@myv 这个用户是使用密码登录,单独在 evn.passwords里面配置. 注意配置的方式是 full host strings 即 用户@IP:port 和 密码.

    密钥的填写 env.key_filename

    gsx@myv 使用 密钥 ./ssh/test
    gsx@myv2 使用 密钥 ./ssh/test8

    将连接使用到的密钥 填入 env.key_filename 列表中,密钥填写顺序无关. 不需要hosts与 key_filename 对应起来, 也不需要长度相等 , fabric 会自己尝试密钥.(May be a string or list of strings, referencing file paths to SSH key files to try when connecting. Passed through directly to the SSH layer. May be set/appended to with -i.)

  • 相关阅读:
    homebrew 安装 mpv
    Spring JdbcTemplate 两种方法的区别
    git .gitignore失效的解决办法
    git 分支修改bug应用场景
    url编码实践
    escape encodeuri encodeURIComponent 区别
    mysql命令gruop by报错this is incompatible with sql_mode=only_full_group_by
    服务器病毒问题解决- 阿里云 挖矿病毒,Circle_MI.png
    trim和replace的陷阱实践
    mysql 5.7.15 union order by 子查询排序不生效
  • 原文地址:https://www.cnblogs.com/cheerupforyou/p/7469626.html
Copyright © 2011-2022 走看看