美文网首页
2020-01-12 ansible use ssh confi

2020-01-12 ansible use ssh confi

作者: 五大RobertWu伍洋 | 来源:发表于2020-04-18 17:14 被阅读0次

    define alias for short input in bash mobaxterm

    alias an="ansible"
    alias ans='ansible --ssh-common-args="-F /home/mobaxterm/.ssh/config"'
    

    use system ssh config file , must use -k , otherwise it fails

    -k will ask for password, then mobaxterm ssh agent will help ssh login after any password typed

    ans all -i "dep," -a "lsb_release -a" -k
    
    an all -i "ng," -a "df -h" (fails)
    an all -i "ng," -a "df -h" -k(works)
    

    strange since -k is only required in ansible 2.9, dev branch is free of it.

    an and ans is an alias of ansible

    dep and ng is host alias configured in .ssh/config file:

    Host 17 dep* depd
    HostName 47.94.xx.xx
    

    below is in ansible.cfg to use ssh client config file:

    [ssh_connection]
    pipelining = True
    ssh_args= -F ~/.ssh/config -o ForwardAgent=yes -o ControlMaster=auto
    

    sample test and result

    use an alias

     周六 2020-04-18  17:01:27  Administrator@RobertNote: /g/Projects/baishan/train/ansible_install/ansible_2.9
    9411 $ an all -i "ng," -a "df -h" -k
    SSH password:
    [WARNING]: Skipping plugin (/g/Projects/baishan/train/ansible_install/ansible_2.9/lib/ansible/plugins/callback/osx_say.py) as it
    seems to be invalid: name 'say' is not defined
    
    Saturday 18 April 2020  17:02:39 +0800 (0:00:00.748)       0:00:00.748 ********
    ng | CHANGED | rc=0 >>
    文件系统        容量  已用  可用 已用% 挂载点
    udev            3.9G  8.0K  3.9G    1% /dev
    tmpfs           799M  456K  799M    1% /run
    /dev/vda1        50G   19G   28G   41% /
    none            4.0K     0  4.0K    0% /sys/fs/cgroup
    none            5.0M     0  5.0M    0% /run/lock
    none            3.9G  4.0K  3.9G    1% /run/shm
    none            100M  4.0K  100M    1% /run/user
    
    Saturday 18 April 2020  17:02:45 +0800 (0:00:06.079)       0:00:06.827 ********
    ===============================================================================
    shell ----------------------------------------------------------------------------------------------------------------------- 6.08s
    Playbook run took 0 days, 0 hours, 0 minutes, 6 seconds
    

    use ans alias as

    9412 $ typa ans
    ans is aliased to `ansible --ssh-common-args="-F /home/mobaxterm/.ssh/config"'
    
    9410 $ ans all -i "dep," -a "lsb_release -a" -k
    SSH password:
    [WARNING]: Skipping plugin (/g/Projects/baishan/train/ansible_install/ansible_2.9/lib/ansible/plugins/callback/osx_say.py) as it
    seems to be invalid: name 'say' is not defined
    
    Saturday 18 April 2020  17:01:20 +0800 (0:00:00.957)       0:00:00.957 ********
    dep | CHANGED | rc=0 >>
    LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2
    -noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:secu
    rity-4.1-noarch
    Distributor ID: Ubuntu
    Description:    Ubuntu 14.04.5 LTS
    Release:        14.04
    Codename:       trusty
    
    Saturday 18 April 2020  17:01:27 +0800 (0:00:06.151)       0:00:07.108 ********
    ===============================================================================
    shell ----------------------------------------------------------------------------------------------------------------------- 6.15s
    Playbook run took 0 days, 0 hours, 0 minutes, 6 seconds
    

    相关文章

      网友评论

          本文标题:2020-01-12 ansible use ssh confi

          本文链接:https://www.haomeiwen.com/subject/lqcwactx.html