ansible 常用模块介绍

回复 收藏
  1. 查看可使用的模块
  2. [root@aliyun-63 ~]# ansible-doc  -l
  3. 查看帮助  
  4. [root@aliyun-63 ~]# ansible-doc   -s yum
  5. 1.setup模块  
  6. 功能:收集系统信息
  7. [root@aliyun-63 ~]# ansible 118 -m  setup
  8. 2.ping 模块
  9. 功能:检测远程主机是否存活
  10. [root@aliyun-63 ~]# ansible 118 -m  ping
  11. 3.file 模块
  12. 功能:新建 删除  目录 文件
  13. value of state must be one of: file,directory,link,hard,touch,absent
  14. [root@aliyun-63 ~]#  ansible 118   -m file -a "path=/tmp/2  state=touch"
  15. [root@aliyun-63 ~]#  ansible 118   -m file -a "path=/tmp/3  state=directory"
  16. [root@aliyun-63 ~]# ansible 118   -m file -a "path=/tmp/3  state=absent"
  17. 4.copy 模块
  18. 功能:本地文件复制到远程主机群,进行统一部署
  19. [root@aliyun-63 ~]# ansible  118   -m  copy  -a  "src=/tmp/63_gcnew.log  dest=/tmp/63_gcnew.log  mode=600"
  20. [root@aliyun-63 ~]# ansible  118   -m  copy  -a  "src=/tmp/63_gcnew.log  dest=/tmp/63_gcnew.log  backup=yes"
  21. 5.command 模块
  22. 功能:远程执行一个命令 如   ls   cat     
  23. [root@aliyun-63 ~]# ansible 118  -m command -a 'creates=/tmp/linuser.txt ls -l /etc/passwd'
  24. creates  前面成立  后面不执行
  25. removes  前面不成立  后面执行
  26. chdir     切换目录
  27. [root@aliyun-63 ~]# ansible 118  -m command -a 'chdir=/tmp  ls '
  28. 6.shell 模块
  29. 功能:command 模块不支持管道命令的执行  它支持
  30. [root@aliyun-63 ~]# ansible 118  -m shell  -a 'cat  /tmp/63_gcnew.log | grep 2016'
  31. 7.yum  模块
  32. 功能: 安装 或者 卸载 软件包
  33. [root@aliyun-63 ~]# ansible 118  -m  yum   -a 'name=lrzsz  state=installed'
  34. [root@aliyun-63 ~]# ansible 118  -m  yum   -a 'name=lrzsz  state=removed'
  35. 8.service 模块
  36. 功能: 对某些服务的启动、重启、停止、重载等的管理
  37. [root@aliyun-63 ~]# ansible 118   -m  yum  -a  'name=redis   state=installed'
  38. [root@aliyun-63 ~]# ansible 118   -m  service  -a  'name=redis   state=started  enabled=yes'
  39. [root@aliyun-63 ~]# ansible 118   -m  shell -a  'netstat  -lnp  | grep  redis'
  40. 9.cron 模块
  41. 功能: 建立计划任务
  42. [root@aliyun-63 ~]# ansible  118 -m cron  -a "name='restart  nginx'  hour=11 user=root job='/opt/nginx/sbin/nginx  -s reload'"
  43. [root@aliyun-63 ~]# ansible 118 -m shell  -a  "crontab  -l  |  tail  -2"
  44. 10.user  模块
  45. 功能: 管理用户的模块
  46. [root@aliyun-63 ~]# ansible 118 -m user -a 'name=ddd  state=present '
  47. [root@aliyun-63 ~]# ansible 118 -m user -a 'name=ddd  state=absent '
  48. 11.synchronize 模块
  49. 功能: 数据同步管理
  50. [root@aliyun-63 yum.repos.d]# ansible  118 -m yum  -a "name=rsync  state=installed"
  51. [root@aliyun-63 sd]# ansible  118 -m  synchronize  -a  'src=/tmp/sd  dest=/tmp/  mode=push delete=yes'
  52. [root@aliyun-63 sd]# ansible  118 -m  synchronize  -a  'src=/tmp/sd  dest=/tmp/  mode=push delete=yes  rsync_opts="-avz,--exclude=Test"'

2016-04-26 11:35 举报
已邀请:
0

alvinnull

赞同来自:

赞一个

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: