美文网首页
ansible 运行 ad hoc 任务

ansible 运行 ad hoc 任务

作者: xuweizhen | 来源:发表于2018-08-01 16:59 被阅读0次

ansible 运行 ad hoc 任务

1. 什么是ad hoc命令

我们敲入一些命令去比较快的完成一些事情,而不需要将这些执行的命令特别保存下来, 这样的命令就叫做 ad-hoc 命令.

2. 为什么要用ad hoc命令

只是需要一个命令就能解决任务的,就使用ad hoc命令。

3. 命令

在所有服务机中执行shell命令10次

ansible atlanta -a "/sbin/reboot" -f 10 -u admin --sudo -k

参数解析:

  • atlanta :服务器组名group
  • -a : all,group下所有机器
  • "/sbin/reboot":shell命令
  • -f:重复执行,+ 数字,表示重复执行几次
  • -k:输入密码,如果没有实现免密登录,就需要使用-k来手动输入密码
  • -u:使用哪一个用户操作远程主机
  • --sudo:在该用户下使用sudo命令执行

ad hoc可以使用各种模块

模块就是ansible中各种非常成熟的工具
copy模块,从本地向远程hosts拷贝文件
file模块,操作远程hosts中文件的模块
使用-m命令选择你需要的模块

$ ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"
  1. 参考文档
    ansible使用ad hoc指南:http://www.ansible.com.cn/docs/intro_adhoc.html
    ansible的模块指南:https://docs.ansible.com/ansible/latest/modules/modules_by_category.html

相关文章

网友评论

      本文标题:ansible 运行 ad hoc 任务

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