zoukankan      html  css  js  c++  java
  • [转] ansible批量执行命令展示

    【From】 https://blog.csdn.net/zhydream77/article/details/81223805

    ansible命令基础


    • ansible <host-pattern> [options]
    host-pattern 主机戒定义的分组
    -M 指定模块路径
    -m 使用模块,默认 command 模块
    -a or --args 模块参数
    -i inventory 文件路径,戒可执行脚本
    -k 使用交亏式登彔密码
    -e 定义变量
    -v 详绅信息,-vvvv 开吭 debug 模式


    • 列出要执行的主机,不执行任何操作
    ansible all --list-hosts


    • 批量检测主机
    ansible all -m ping


    • 批量执行命令
    ansible all -m command -a 'id' -k


    批量部署证书文件
    • 每次交亏输入密码比较麻烦
    • 密码写入配置文件安全性很差
    • 不同主机不同密码,配置文件要上天
    • 使用 key 方式认证,是一个不错的选择
    • 给所有主机部署公钥

    ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(</root/.ssh/authorized_keys)'" -k -v

    举例说明:

    批量检测主机
    [root@ansible ~]# ansible web  -m ping

    批量执行命令
    [root@ansible ~]# ansible all -m command -a 'uptime'
    [root@ansible ~]# ansible web  -m command -a 'uptime'
    [root@ansible ~]# ansible web  -m command -a 'uptime' -k
    SSH password: 
    web1 | SUCCESS | rc=0 >>
     14:37:12 up  5:12,  3 users,  load average: 0.01, 0.03, 0.02

    web2 | SUCCESS | rc=0 >>
     14:37:12 up  5:03,  2 users,  load average: 0.00, 0.01, 0.03

    批量部署证书文件
    [root@ansible ooxx]# ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(</root/.ssh/id_rsa.pub)'" -k  

    注意:

    /root/.ssh/id_rsa.pub是通过命令生成的ssh-keygen -t rsa并且在/root/.ssh/目录下可以看到的
    ---------------------
    作者:zhy-dream
    来源:CSDN
    原文:https://blog.csdn.net/zhydream77/article/details/81223805
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    使用mybatis如果类属性名和数据库中的属性名不一样取值就会为null
    学习mybatis时出现了java.io.IOException: Could not find resource EmployeeMapper.xml
    配置mybatis-config.xml出现过很诡异的现象
    mybatis学习(一)
    报错cannot be cast to javassist.util.proxy.Proxy
    列车调度
    三角形
    土豪聪要请客(stol)
    Jams倒酒(pour)
    Data
  • 原文地址:https://www.cnblogs.com/pekkle/p/10905552.html
Copyright © 2011-2022 走看看