zoukankan      html  css  js  c++  java
  • ansible安装和批量执行命令

    yum install -y ansible

       

       

    编辑 /etc/ansible/hosts 文件

       

    # This is the default ansible 'hosts' file.
    #
    # It should live in /etc/ansible/hosts
    #
    # - Comments begin with the '#' character #
    #来表示注释
    # - Blank lines are ignored #
    空白行被忽略
    # - Groups of hosts are delimited by [header] elements #
    主机组 需要在【】下面
    # - You can enter hostnames or ip addresses #
    可以写主机名或者ip地址
    # - A hostname/ip can be a member of multiple groups #
    一台主机可以在多个组里面

       

    [web] #客户端组

    192.168.181.133 #客户局IP地址

    192.168.181.134

       

    批量执行web组中的命令

    ansible web -m shell -a "ifconfig eth0 | awk -F '[:. ]+' 'NR==2{print $6}'"

       

    双引号内的命令体,shell也可以换成command 两者的区别是command不支持例如管道符之类的特殊符号。

       

    传送本地文件到客户机上

    ansible group1 -m copy -a "src=/root/xmr.sh dest=/root/"

       

    运行客户机上的脚本文件

       

    ansible group1 -m shell -a "sh /root/xmr.sh"

  • 相关阅读:
    并查集
    强联通分量,缩点
    最短路径
    最小生成树
    拓扑排序
    图的遍历
    图论基础知识
    数据库四种隔离级别
    MySQL 索引 乐观锁 悲观锁
    MYSQL+正则
  • 原文地址:https://www.cnblogs.com/withfeel/p/14267119.html
Copyright © 2011-2022 走看看