美文网首页
第三十九天ansible自动化管理2

第三十九天ansible自动化管理2

作者: 学无止境_9b65 | 来源:发表于2019-05-05 08:39 被阅读0次

    上节内容回顾加实践

    41是管理机:
    41----->61
    41----->31


    image.png

    1)在41上配置ansible

    !/bin/bash

    yum install ansible -y
    ssh-keygen -f ~/.ssh/id_rsa -P '' -q
    for ip in 31 61
    do
    sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.$ip
    done

    test

    ssh 172.16.1.61 "ifconfig eth0"
    ssh 172.16.1.31 "ifconfig eth0"

    2)ansible基本配置

    [root@backup ~]# cat /etc/ansible/hosts
    [oldboy]
    172.16.1.31
    172.16.1.61

    vim /etc/ansible/ansible.cfg +374
    结尾增加: -o StrictHostKeyChecking=no
    ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no

    3)使用ansible
    [root@backup ~]# ansible oldboy -m command -a "free -m"
    172.16.1.31 | CHANGED | rc=0 >>
    total used free shared buff/cache available
    Mem: 972 79 791 7 101 757
    Swap: 767 0 767

    172.16.1.61 | CHANGED | rc=0 >>
    total used free shared buff/cache available
    Mem: 972 66 768 7 137 754
    Swap: 767 0 767

    4)查看使用帮助
    ansible-doc -l #模块就Linux命令了。
    command Executes a command on a remote node

    查模块的参数:
    ansible-doc -s command #Linux命令参数

    相关文章

      网友评论

          本文标题:第三十九天ansible自动化管理2

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